We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19910
    • 8 Posts
    I have a problem with BabelTranslation.
    It doesn't return anything. I tried to call it in different ways but no luck:

    [[BabelTranslation? &contextKey=`en`]]
    [[BabelTranslation? &resourceId=`12`&contextKey=`[[++cultureKey]]`]]


    Any idea what could be wrong?
    Thanks! [ed. note: mnaco last edited this post 14 years, 10 months ago.]
      • 31946
      • 116 Posts
      Hi mnaco.
      The resourceId is optional (it will take the current resourceID by default), but you must tell the Snippet in which contex you are searching the translated resource. So in your call, contextKey cannot be empty.
      Also I think if there's no translated resource found, the Snippet returns nothing.
        • 19910
        • 8 Posts
        Thanks Wanze, I just updated my replay with the sample how I've tried to use the snippet.
          • 37582
          • 65 Posts
          Hey mnaco,

          both seems to be correct. However, did you check whether your resources are linked correctly? Which means, did you use the link translation function of Babel?
            • 31946
            • 116 Posts
            Hi mnaco,
            I just testet the Snippet on one of my sites with Revo 2.2 cr3. I have the default context web for german, and a context "fr" for french. I called both your lines in my template, instead of "en" i used "fr".
            The first call does work for me, the second doesn't work, because the cultureKey is set to the loaded language... so it makes no scence to get a Translation for german when german is loaded.

            Where did you call the snippet? Is the resource translated with babel?
            Did you clear the cache?
              • 19910
              • 8 Posts
              Thanks for your replay!

              I have three languages and seems everything fine with resources. At least BabelLinks works fine and all resources linked correctly. Problem is the BabelTranslation.

              I call the the snippet in the template and cache cleared.

                • 19910
                • 8 Posts
                I just want to share some more information may help to find what's wrong with BabelTranslation.

                As mentioned I use three languages - English, Armenian and Russian.
                Do you think the problem could be the language(s) don't come with Babel and something needs to be configured additionally (well except lexicon)?

                All resources I added linked and works correctly.

                The contexts added and below please the gateway plugin I'm using.

                <?php
                if($modx->context->get('key') != "mgr"){
                    /* grab the current langauge from the cultureKey request var */
                    switch ($_REQUEST['cultureKey']) {
                        case 'en':
                            /* switch the context */
                            $modx->switchContext('eng');
                            break;
                        case 'am':
                            /* switch the context */
                            $modx->switchContext('arm');
                            break;
                        default:
                            /* Set the default context here */
                            $modx->switchContext('web');
                            break;
                    }
                    /* unset GET var to avoid
                     * appending cultureKey=xy to URLs by other components */
                    unset($_GET['cultureKey']);
                }
                


                .htaccess file also updated related with Friednly URLs

                # The Friendly URLs part
                # detect language when requesting the root (/)
                RewriteCond %{HTTP:Accept-Language} !^(en|am|ru) [NC]
                RewriteRule ^$ am/ [R=301,L]
                RewriteRule ^$ ru/ [R=301,L]
                RewriteRule ^$ en/ [R=301,L]
                 
                # redirect all requests to /en/favicon.ico /ru/favicon.ico and /am/favicon.ico
                # to /favicon.ico
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteRule ^(en|ru|am)/favicon.ico$ favicon.ico [L,QSA]
                 
                # redirect all requests to /en/assets* /ru/assets* and /am/assets* to /assets*
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteRule ^(en|ru|am)/assets(.*)$ assets$2 [L,QSA]
                 
                # redirect all other requests to /en/* /ru/* and /am/*
                # to index.php and set the cultureKey parameter
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteRule ^(en|ru|am)?/?(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]
                
                .

                Please let me know if you need any idea how to get BabelTranslation working.
                Thank you!
                  • 19910
                  • 8 Posts
                  Anybody can help please
                  I have tried another fresh installation (2.1.5-pl) added two languages (de and en). Everything seems to work fine except BabelTranslation.
                    • 19910
                    • 8 Posts
                    Seems to fix this issue I need to set the same name for Context and Culture Key or modify the 'gateway' plugin.
                    Babel uses contextKey parameter and in my case
                    [[BabelTranslation? &resourceId=`12`&contextKey=`[[++cultureKey]]`]]
                    contextKey and cultureKey should have same names (en-en, am-am, ru-ru. currently i have en-eng, am-arm, web-ru, so contextKey=`[[++cultureKey]]` simply doesn't work).
                      • 19910
                      • 8 Posts
                      FIXED !
                      Replaced ++cultureKey with *context_key and evertyhign works fine now.

                      [[BabelTranslation? &contextKey=`[[*context_key]]`