• MODX Internationalization [Solved]#

  • DESIGNfromWITHIN Reply #1, 5 months, 2 weeks ago

    Reply
    I wrote this post:
    MODX Multilingual – Setting up Babel http://designfromwithin.com/blog/995/modx-multilingual-setting-up-babel/
    It seems a lot of people are struggling with this.

    Following this tut does not work 100%:
    http://www.multilingual-modx.com/blog/2011/seo-friendly-multilingual-websites-with-modx-and-babel.html
    I changed the tut a bit and I have got it to work now, but not exactly the way I want it.

    What is working now:

    What I would like:

    The issue:
    How do I get the root link to work without having /com/en/ added behind it?

    Some of the code used:

    .htaccess:
    RewriteEngine On
    RewriteBase /
    ....
    # Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
    RewriteCond %{HTTP_HOST} .
    RewriteCond %{HTTP_HOST} !^your-website-url\.com [NC]
    RewriteRule (.*) http://your-website-url.com/$1
     [R=301,L]
    ....
    # The Friendly URLs part
    # detect language when requesting the root (/)
    RewriteCond %{HTTP:Accept-Language} !^(en|nl|de) [NC]
    RewriteRule ^$ en/ [R=301,L]
    RewriteRule ^$ nl/ [R=301,L]
    RewriteRule ^$ de/ [R=301,L]
     
    # redirect all requests to /de/favicon.ico and /nl/favicon.ico
    # to /favicon.ico
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(en|de|nl)/favicon.ico$ favicon.ico [L,QSA]
     
    # redirect all requests to /de/assets* and /nl/assets* to /assets*
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(en|de|nl)/assets(.*)$ assets$2 [L,QSA]
     
    # redirect all other requests to /de/* and /nl/*
    # to index.php and set the cultureKey parameter
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(en|de|nl)?/?(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]
    


    Lexicons:
    base_url: /nl/
    cultureKey: nl
    site_start: 11
    site_url: http://www.modxtutorials.com/nl/

    base_url: /de/
    cultureKey: de
    site_start: 22
    site_url: http://www.modxtutorials.com/de/

    base_url: /en/
    cultureKey: en
    site_start: 1
    site_url: http://www.modxtutorials.com/en/

    I have tried this, does not work:
    base_url: /
    cultureKey: en
    site_start: 1
    site_url: http://www.modxtutorials.com/

    Gateway plugin (OnHandleRequest checked):
    <?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, 'cultureKey');
            if ( isset( $_REQUEST[$cntxt_param] ) && $_REQUEST[$cntxt_param] != '' ) {
                switch ( $_REQUEST[$cntxt_param] ) {
     
                    case 'nl':
                    $modx->switchContext('Nederlands');
                    $modx->setOption('cultureKey', 'nl');
                    break;
     
                    case 'de':
                    $modx->switchContext('Deutsch');
                    $modx->setOption('cultureKey', 'de');
                    break;
     
                    default:
                    // Set the default language/context here
                    $modx->switchContext('web');
                    $modx->setOption('cultureKey', 'en');
                    break;
                }
            }
        }
    ?>
    


  • strochli Reply #2, 5 months, 2 weeks ago

    Reply
    What helped for me was:

    1. Disable language detection in the .htaccess (lines 12-15)
    2. Remove all "en|" entries in the .htaccess as this is the default language
    3. Context settings

    web
    base_url: /
    cultureKey: en
    site_start: 1
    site_url: http://mysite.com/

    Nederlands
    base_url: /nl/
    cultureKey: nl
    site_start: 11
    site_url: http://mysite.com/nl/

    Deutsch
    base_url: /de/
    cultureKey: de
    site_start: 22
    site_url: http://mysite.com/de/

    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, 'cultureKey');
        if ( isset( $_REQUEST[$cntxt_param] ) && $_REQUEST[$cntxt_param] != '' ) {
        switch ( $_REQUEST[$cntxt_param] ) {
     
            case 'nl':
            $modx->switchContext('nl');
            break;
    		
    	case 'de':
            $modx->switchContext('de');
            break;
     
    	default:
            // nothing because web is default
            break;
        }
    	$modx->setPlaceholder('context_key', $modx->context->get( 'key' ));
        }
    }
    


    4. Install Babel after you did all the settings.


  • DESIGNfromWITHIN Reply #3, 5 months, 2 weeks ago

    Reply
    You sir, Are my personal hero now!

    My gateway plugin is a bit different but this works for me:
    <?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 'nl':
              $modx->switchContext('Nederlands');
              $modx->setOption('cultureKey', 'nl');
              break;
    
            case 'de':
              $modx->switchContext('Deutch');
              $modx->setOption('cultureKey', 'de');
              break;
              
            default:
            // nothing because web is default
            break;
    
          }
        }
      }