We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29597 ☆ A M B ☆
    • 350 Posts
    My client has a newsletter with links like:
    http://somesite.com/singnup.com

    The client's website is multiligual (English: http://somesite.com/en/, German: http://somesite.com/de/ and French: http://somesite.com/fr/)
    This part is working fine, I have Babel and Redirector installed.

    They want to redirect the link of the newsletter to a specific page.

    Can anybody help to to do this?
      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
      • 36561
      • 38 Posts
      You could write a snippet to check the HTTP_ACCEPT_LANGUAGE like:

      $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
      switch ($lang){
          case "fr":
              //redirect to FR
              break;
          case "en":
              //redirect to EN
              break;
          default:
              //redirect to DE
              break;
      }
      


      A good overview of some more advanced methods to check for HTTP_ACCEPT_LANGUAGE can be found in this thread on stackoverflow:
      http://stackoverflow.com/questions/3770513/detect-browser-language-in-php

        • 29597 ☆ A M B ☆
        • 350 Posts
        Thanks, can you help a bit more and tell me where I should load/place this snippet?
        I broke my DEV by activating it on page load...

        I already use a gateway plugin:

        <?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');
                  //set the cultureKey
                  $modx->setOption('cultureKey', 'en');
                  break;
                  
                case 'fr':
                  $modx->switchContext('fr');
                  $modx->setOption('cultureKey', 'fr');
                  break;
                  
               case 'de':
                  $modx->switchContext('de');
                  $modx->setOption('cultureKey', 'de');
                  break;
        
               case 'it':
                  $modx->switchContext('it');
                  $modx->setOption('cultureKey', 'it');
                  break;
                  
                default:
                  // Set the default language/context here
                  break;
              }
            }
          }
        


        This works fine, Babel works, and if I change my browser language to German, http://mysite.com gets redirected to http://mysite.com/de/

        The problem is that a link http://mysite.com/signup always goes to http://mysite.com/en/signup even if the language setting is German...
        In Redirector the link signup is redirected to signup.html but it is always selecting the EN language.... [ed. note: ThaClown last edited this post 13 years, 10 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
          • 36561
          • 38 Posts
          I would have placed the snippet on the http://mysite.com/signup page.

          Maybe this is a hack, but why not exclude the signup page from your plugin:

          <?php
          // disable plugin for these resources
          $exclude_pages = array(23, 34);
          //make sure the plugin does not run on the mgr context (the manager)
            if ( $modx->context->get( 'key' ) != 'mgr' && !in_array($modx->resource->get('id'),$excluded_pages) ) {
          [...]