We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    If you're going to use $_SERVER["HTTP_ACCEPT_LANGUAGE"] (and it's not a bad way to go for new visitors), keep in mind that it can be an array of weighted options:

    http://www.dyeager.org/blog/2008/10/getting-browser-default-language-php.html

      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
      • 19604 ☆ A M B ☆
      • 179 Posts
      Yes, Bob, absolutely right. I only aimed for the first language choice. This can/should be improved.

      P.S.: dyeager.org? Oh boy, some strange other stuff can be found there... ;-)
        MINDEFFECTS – DESIGN for PRINT, WEB and MEDIA
        http://twitter.com/mindeffects · http://www.facebook.com/mindeffects · http://www.youtube.com/mindeffects/ · skype://mindeffects_oliver
        • 3749
        • 24,544 Posts
        No kidding. wink Case in point: http://www.dyeager.org/blog/2013/01/wile-e-coyotes-guide-to-offense.html

        I chose it because it's the best explanation and implementation of how to handle HTTP_ACCEPT_LANGUAGE that I could find.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 19604 ☆ A M B ☆
          • 179 Posts
          Quote from: BobRay at Jan 25, 2013, 08:29 PM
          No kidding. wink Case in point: http://www.dyeager.org/blog/2013/01/wile-e-coyotes-guide-to-offense.html

          I chose it because it's the best explanation and implementation of how to handle HTTP_ACCEPT_LANGUAGE that I could find.
          Yep, that's what my research results were, too: else I would have quoted them here. wink
          So we might as well tap out out for his language-q-thing-explanation, since it's a good one... But I will still write my own code. smiley
          P.S.: So glad you used that smily wink in your reply!
            MINDEFFECTS – DESIGN for PRINT, WEB and MEDIA
            http://twitter.com/mindeffects · http://www.facebook.com/mindeffects · http://www.youtube.com/mindeffects/ · skype://mindeffects_oliver
            • 29597 ☆ A M B ☆
            • 350 Posts
            Quote from: donquicky at Jan 25, 2013, 04:40 PM
            I'am also afraid that it evaluates the system setting. In your script the cultureKey is set based on language served. Consider setting cultureKey by default on each context and not in a script. That way I believe the Redirector extra will redirect fine!

            Thanks, I tried this:

            Set [[++cultureKey]] in every context

            Updated .htaccess
            <?php
            //make sure the plugin does not run on the mgr context (the manager)
              if ( $modx->context->get( 'key' ) != 'mgr') {
                /**
                 * grab the current context from the request "c" parameter (or context_param_alias from system settings)
                 * the alternative .htaccess friendly URL rewrite rule must be activated
                 */
                $cntxt_param = $modx->getOption('context_param_alias', null, 'c');
                if ( isset( $_REQUEST[$cntxt_param] ) && $_REQUEST[$cntxt_param] != '' ) {
                  switch ( $_REQUEST[$cntxt_param] ) {
                        
                    case 'en':
                      //switch the context
                      $modx->switchContext('web');
                      break;
                        
                    case 'fr':
                      $modx->switchContext('fr');
                      break;
                        
                   case 'de':
                      $modx->switchContext('de');
                      break;
              
                   case 'it':
                      $modx->switchContext('it');
                      break;
                        
                    default:
                      switch ( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) {
                    
                       case 'fr':
                          $modx->switchContext('fr');
                          break;
                            
                       case 'de':
                          $modx->switchContext('de');
                          break;
                     
                       case 'it':
                          $modx->switchContext('it');
                          break;
                            
                        default:
                          $modx->switchContext('web');
                          //set the cultureKey
                          break;
                      }
                  }
                }
              }
            


            In Redirector:

            promo.html > [[!++cultureKey]]/promotion.html
            Gets redirected to: http://mysite.com/en/en/promotion.html (with every language setting it goes to EN)

            or

            promo.html > promotion.html
            Gets redirected to: http://mysite.com/en/promotion.html (with every language setting it goes to EN)

            also

            promo.html > http://mysite.com/[[++cultureKey]]/promotion.html
            http://mysite.com/en/promotion.html (with every language setting it goes to EN)

            So not there yet...

            The Redirector code is:

            <?php
            /**
             * @package redirector
             */
            /* load redirector class */
            $corePath =  $modx->getOption('redirector.core_path',$scriptProperties,$modx->getOption('core_path').'components/redirector/');
            $redirector = $modx->getService('redirector','Redirector',$corePath.'model/redirector/',$scriptProperties);
            if (!($redirector instanceof Redirector)) return '';
            
            /* handle redirects */
            $search = $_SERVER['REQUEST_URI'];
            $baseUrl = $modx->getOption('base_url',null,MODX_BASE_URL);
            if (!empty($baseUrl) && $baseUrl != '/' && $baseUrl != ' ') {
                $search = str_replace($baseUrl,'',$search);
            }
            $search = ltrim($search,'/');
            $extPos = strrpos($search, '.');
            if ($extPos) {
                if ($search) {
                    $redirect = $modx->getObject('modRedirect', array(
                        'pattern' => $search,
                        'active' => 1,
                    ));
                    if ($redirect) {
                        $target = $redirect->get('target');
                        $modx->parser->processElementTags('', $target, true, true);
                        if ($target != $modx->resourceIdentifier && $target != $search) {
                            if (!strpos($target, '://')) {
                                $target = $modx->getOption('site_url').$target;
                            }
                            $modx->log(modX::LOG_LEVEL_INFO, 'Redirector plugin redirecting request for ' . $search . ' to ' . $target);
                            header('HTTP/1.1 301 Moved Permanently');
                            $modx->sendRedirect($target);
                        }
                    }
                }
                $search = substr($search, 0, $extPos);
            }
            if ($search) {
                $redirect = $modx->getObject('modRedirect', array('pattern' => $search, 'active' => 1));
                if ($redirect) {
                    $target = $redirect->get('target');
                    $modx->parser->processElementTags('', $target, true, true);
                    if ($target != $modx->resourceIdentifier && $target != $search) {
                        if (!strpos($target, '://')) {
                            $target = $modx->getOption('site_url').$target;
                        }
                        $modx->log(modX::LOG_LEVEL_INFO, 'Redirector plugin redirecting request for ' . $search . ' to ' . $target);
                        header('HTTP/1.1 301 Moved Permanently');
                        $modx->sendRedirect($target);
                    }
                }
            }
            return;
            


            Maybe I can modify it? [ed. note: ThaClown last edited this post 13 years, 8 months ago.]
              MODX Ambassador (NL) | Responsive web design specialist, developer & speaker
              DESIGNfromWITHIN, MPThemes and Any Screen Size
              Follow me on Twitter | Read my blog | My code on GitHub
              • 19604 ☆ A M B ☆
              • 179 Posts
              There is a system setting that allows/permits cross-context-links. Don't know the exact name. This might suppress the language dependent jumps in your case. Just guessing.
                MINDEFFECTS – DESIGN for PRINT, WEB and MEDIA
                http://twitter.com/mindeffects · http://www.facebook.com/mindeffects · http://www.youtube.com/mindeffects/ · skype://mindeffects_oliver
                • 37105
                • 194 Posts
                @mindeffects: is the setting "allow_forward_across_contexts" you are looking for?
                  Codeplaza Webdesign: for professional websites at low cost
                  • 19604 ☆ A M B ☆
                  • 179 Posts
                  Yep. Maybe this setting keeps Menno's script from working.

                  P.S.: I am on the iPad today, so I could not use the manager (C'mon, WTF?!) to look it up.
                    MINDEFFECTS – DESIGN for PRINT, WEB and MEDIA
                    http://twitter.com/mindeffects · http://www.facebook.com/mindeffects · http://www.youtube.com/mindeffects/ · skype://mindeffects_oliver
                    • 37105
                    • 194 Posts
                    Maybe the extra HandyMan [ http://modx.com/extras/package/handyman ] made by Mark Hamstra is an option for you to manage MODX from devices like tablets and mobile phones.
                      Codeplaza Webdesign: for professional websites at low cost
                      • 19604 ☆ A M B ☆
                      • 179 Posts
                      Quote from: donquicky at Jan 27, 2013, 04:32 PM
                      Maybe the extra HandyMan [ http://modx.com/extras/package/handyman ] made by Mark Hamstra is an option for you to manage MODX from devices like tablets and mobile phones.
                      This would most certainly be a solution. But I don't want to install HandyMan on all of my 30something MODX installations just to be prepared for a mobile access situation. I think, the manager should arrive in the touch-device-age. And, as I understood MODX's Kevin, there will be solutions for that in the upcoming MODX releases. Hopefully in 2.3 but I am afraid it will be in 3.0.

                      P.S.: Just take a look at the HTML structure of something as simple as a "listbox" in the manager, like the one for choosing a template. There is a simple HTML-tag for these kind of input fields. You see the neccecary code needed for this ”thing“ to work in MODX? Now you know where the speed of the Revolution went (@Bob: Talking about ”Evolution“, again. Funny! ;-)
                        MINDEFFECTS – DESIGN for PRINT, WEB and MEDIA
                        http://twitter.com/mindeffects · http://www.facebook.com/mindeffects · http://www.youtube.com/mindeffects/ · skype://mindeffects_oliver