On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Hi, i did a website some years ago and i wanted to use MODx with it.
    It's a website that has 2 languages: spanish and english, so i decided to try Babel.

    I did this tutorial:
    http://www.youtube.com/watch?v=pLyrSDwlh4w
    http://designfromwithin.com/blog/995/modx-multilingual-setting-up-babel/

    And something is not working.
    My babel links for language works but the assets path is wrong and the links points to my default language.

    http://apaca.com.ve/en/nosotros.html
    http://apaca.com.ve/nosotros.html

    I did a test (thanks to Jay Gilmore) with hardcoded base href and my assets showed ok.

    Here's the code, i would really appreciate some help.

    My Template:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>:: APACA ::</title>
      <base href="http://apaca.com.ve" />
    <script src="Scripts/swfobject_modified.js" type="text/javascript"></script>
    <script src="SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script>
    <script src="SpryAssets/SpryCollapsiblePanel.js" type="text/javascript"></script>
    <style type="text/css">
    <!--
    .idioma {
    	font-size: x-small;
    }
    body {
    	margin-top: 0px;
    	color: #666;
    	font-size: small;
    	margin-bottom: 0px;
    	background-image: url(https://modx-iglusjax.stackpathdns.com/img/bg.gif);
    }
    body,td,th {
    	font-family: Arial, Helvetica, sans-serif;
    	font-size: small;
    }
    .titulo {
    	font-size: small;
    	font-weight: bold;
    }
    .justficado {
    	text-align: left;
    }
    #TabbedPanels1 .TabbedPanelsContentGroup .TabbedPanelsContent.TabbedPanelsContentVisible table tr td {
    	color: #666;
    }
    #TabbedPanels1 .TabbedPanelsContentGroup .TabbedPanelsContent.TabbedPanelsContentVisible table {
    	color: #FFF;
    }
    -->
    </style>
    <link href="SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
    <link href="apaca_style.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
    <!--
    a:link {
    	color: #000;
    	text-decoration: none;
    }
    a:visited {
    	text-decoration: none;
    	color: #000;
    }
    a:hover {
    	text-decoration: underline;
    }
    a:active {
    	text-decoration: none;
    }
    .idioma p .idioma a {
    	color: #666;
    }
    -->
    </style>
    <link href="SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
    <link href="/SpryAssets/SpryCollapsiblePanel.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
    <!--
    a:link {
    	text-decoration: none;
    }
    a:visited {
    	text-decoration: none;
    }
    a:hover {
    	text-decoration: underline;
    }
    a:active {
    	text-decoration: none;
    }
    -->
    </style>
    <script type="text/javascript">
    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }
    function MM_swapImgRestore() { //v3.0
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }
    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }
    
    function MM_swapImage() { //v3.0
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
       if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }
    </script>
    <link rel="stylesheet" href="http://modx.com/assets/components/discuss/themes/modx/css/index.css" type="text/css" />
    <script type="text/javascript" src="http://modx.com/assets/components/discuss/themes/modx/js/jquery-1.6.1.min.js"></script>
    <script type="text/javascript" src="http://modx.com/assets/components/discuss/themes/modx/js/jquery.scrollTo-min.js"></script>
    <script type="text/javascript" src="http://modx.com/assets/components/discuss/themes/modx/js/discuss.js"></script>
    <script type="text/javascript" src="http://modx.com/assets/components/discuss/themes/modx/js/sh/shCore.js"></script>
    <script type="text/javascript" src="http://modx.com/assets/components/discuss/themes/modx/js/sh/shAutoloader.js"></script>
    <script type="text/javascript" src="http://modx.com/assets/components/discuss/themes/modx/js/sh/shDiscuss.js"></script>
    <script type="text/javascript" src="http://modx.com/assets/components/discuss/themes/modx/js/dis.sticky.js"></script>
    <script type="text/javascript">// <![CDATA[
    DIS.url = "/";DIS.shJsUrl = "http://modx.com/assets/components/discuss/themes/modx/js/sh/";DIS.config.connector = "http://modx.com/assets/components/discuss/connector.php"
    // ]]></script>
    <script type="text/javascript" src="http://modx.com/assets/components/discuss/themes/modx/js/dis.post.modify.js"></script>
    <script type="text/javascript" src="http://modx.com/assets/components/discuss/themes/modx/js/dis.post.buttons.js"></script>
    </head>
    
    <body onload="MM_preloadImages('img/home_hover_s1.gif','img/nosotros_hover_s1.gif','img/productos_hover_s1.gif','img/servicios_hover_s1.gif','img/contacto_hover_s1.gif')">
    <table width="954" border="0" align="center" cellpadding="0" cellspacing="0" background="img/bg_table.gif">
      <tr>
        <th width="4" rowspan="4" scope="col"><table width="100%" border="0" cellspacing="0" cellpadding="0" background="">
          <tr>     </tr>
        </table></th>
        <th width="946" scope="col">
        
        [[$header]] 
        
        </th>
        <th width="10" rowspan="5" scope="col"> </th>
      </tr>
      <tr>
        <td align="center"><img src="img/nos_bar.jpg" width="942" height="28" /></td>
      </tr>
      <tr>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="2">
            <tr>
              <td width="268" rowspan="2" valign="top"><img src="img/nos_apaca.jpg" width="258" height="508" alt="APACA" /></td>
              <td valign="top"> </td>
              <td colspan="2" rowspan="2" valign="top"><p>
    	    
    	  [[*content]] 
    	    
              </p></td>
              <td width="8" rowspan="2" valign="top"> </td>
            </tr>
            <tr>
              <td width="10" valign="top" class="descripcion"> </td>
            </tr>
        </table></td>
      </tr>
      <tr>
        <td bgcolor="#EDE9E1">
        
        [[$quickaccess]] 
        
        </td>
      </tr>
      <tr>
        <td width="4"> </td>
        <td>
        
         [[$footer]]  
        
        </td>
      </tr>
    </table>
    <script type="text/javascript">
    <!--
    swfobject.registerObject("FlashID");
    var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");
    var CollapsiblePanel2 = new Spry.Widget.CollapsiblePanel("CollapsiblePanel2", {contentIsOpen:false});
    var CollapsiblePanel = new Spry.Widget.CollapsiblePanel("CollapsiblePanel", {contentIsOpen:false});
    var CollapsiblePanel4 = new Spry.Widget.CollapsiblePanel("CollapsiblePanel4", {contentIsOpen:false});
    var CollapsiblePanel3 = new Spry.Widget.CollapsiblePanel("CollapsiblePanel3", {contentIsOpen:false});
    //-->
    </script>
    <script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </script>
    <script type="text/javascript">
    try {
    var pageTracker = _gat._getTracker("UA-651229-4");
    pageTracker._trackPageview();
    } catch(err) {}</script>
    <script type="text/javascript">
            var DISModifyPost = $(function() {
                DIS.config.attachments_max_per_post = 5;
                DIS.DISModifyPost.init({
                    attachments: 1
                });
            });</script>
    </body>
    </html>
    
    




    .htaccess

    # MODX supports Friendly URLs via this .htaccess file. You must serve web
    # pages via Apache with mod_rewrite to use this functionality, and you must
    # change the file name from ht.access to .htaccess.
    #
    # Make sure RewriteBase points to the directory where you installed MODX.
    # E.g., "/modx" if your installation is in a "modx" subdirectory.
    #
    # You may choose to make your URLs non-case-sensitive by adding a NC directive
    # to your rule: RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]
    
    RewriteEngine On
    RewriteBase /
    
    
    
    # Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
    RewriteCond %{HTTP_HOST} .
    RewriteCond %{HTTP_HOST} !^apaca\.com.ve [NC]
    RewriteRule (.*) http://apaca.com.ve/$1 [R=301,L]
    #
    # or for the opposite domain.com -> www.domain.com use the following
    # DO NOT USE BOTH
    #
    #RewriteCond %{HTTP_HOST} .
    #RewriteCond %{HTTP_HOST} !^www\.example-domain-please-change\.com [NC]
    #RewriteRule (.*) http://www.example-domain-please-change.com/$1 [R=301,L]
    
    
    
    # Rewrite secure requests properly to prevent SSL cert warnings, e.g. prevent 
    # https://www.domain.com when your cert only allows https://secure.domain.com
    #RewriteCond %{SERVER_PORT} !^443
    #RewriteRule (.*) https://example-domain-please-change.com.com/$1 [R=301,L]
    
    
    
    # The Friendly URLs part
    # detect language when requesting the root (/)
    RewriteCond %{HTTP:Accept-Language} !^(en|es) [NC]
    RewriteRule ^$ en/ [R=301,L]
    RewriteRule ^$ es/ [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|es)/favicon.ico$ favicon.ico [L,QSA]
    
    # redirect all requests to /en/css* and /fr/css* to /css*
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(en|es)/css(.*)$ css$2 [L,QSA]
    
    # redirect all requests to /en/css* and /fr/css* to /css*
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(en|es)/ima(.*)$ css$2 [L,QSA]
    
    # redirect all requests to /de/assets* and /nl/assets* to /assets*
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(en|es)/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|es)?/?(.*)$ index.php?cultureKey=$1&q=$2 [L,QSA]
    
    
    
    # Make sure .htc files are served with the proper MIME type, which is critical
    # for XP SP2. Un-comment if your host allows htaccess MIME type overrides.
    
    #AddType text/x-component .htc
    
    
    
    # If your server is not already configured as such, the following directive
    # should be uncommented in order to set PHP's register_globals option to OFF.
    # This closes a major security hole that is abused by most XSS (cross-site
    # scripting) attacks. For more information: http://php.net/register_globals
    #
    # To verify that this option has been set to OFF, open the Manager and choose
    # Reports -> System Info and then click the phpinfo() link. Do a Find on Page
    # for "register_globals". The Local Value should be OFF. If the Master Value
    # is OFF then you do not need this directive here.
    #
    # IF REGISTER_GLOBALS DIRECTIVE CAUSES 500 INTERNAL SERVER ERRORS :
    #
    # Your server does not allow PHP directives to be set via .htaccess. In that
    # case you must make this change in your php.ini file instead. If you are
    # using a commercial web host, contact the administrators for assistance in
    # doing this. Not all servers allow local php.ini files, and they should
    # include all PHP configurations (not just this one), or you will effectively
    # reset everything to PHP defaults. Consult www.php.net for more detailed
    # information about setting PHP directives.
    
    #php_flag register_globals Off
    
    
    
    # For servers that support output compression, you should pick up a bit of
    # speed by un-commenting the following lines.
    
    #php_flag zlib.output_compression On
    #php_value zlib.output_compression_level 5
    
    
    
    # The following directives stop screen flicker in IE on CSS rollovers. If
    # needed, un-comment the following rules. When they're in place, you may have
    # to do a force-refresh in order to see changes in your designs.
    
    #ExpiresActive On
    #ExpiresByType image/gif A2592000
    #ExpiresByType image/jpeg A2592000
    #ExpiresByType image/png A2592000
    #BrowserMatch "MSIE" brokenvary=1
    #BrowserMatch "Mozilla/4.[0-9]{2}" brokenvary=1
    #BrowserMatch "Opera" !brokenvary
    #SetEnvIf brokenvary 1 force-no-vary
    


    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 'en':
    						$modx->switchContext('English');
    						break;
    
    						default:
    						// nothing because web is default
    						break;
    
    
    
    
    					}
    				}
    			}
    


    The contexts are attached. [ed. note: juanmardila last edited this post 7 years, 10 months ago.]
    • It seams like your htaccess is a little off here:

      # redirect all requests to /en/css* and /fr/css* to /css*
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^(en|es)/css(.*)$ css$2 [L,QSA]
       
      # redirect all requests to /en/css* and /fr/css* to /css*
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^(en|es)/ima(.*)$ css$2 [L,QSA]
      


      Shouldn't it be something more like:

      # redirect all requests to /en/css* and /fr/css* to /css*
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^(en|es)/css(.*)$ css$2 [L,QSA]
       
      # redirect all requests to /en/ima* and /fr/ima* to /ima*
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^(en|es)/ima(.*)$ image$2 [L,QSA]
      
      


      I am guessing "ima" is for your images, if not tweak that accordingly.
        Patrick | Server Wrangler
        About Me: Website | TweetsMODX Hosting
      • Thanks AMDBuiler, that fixed all.
        I just added 2 additional reddirects and it works ok now.

        The only problem that i'm having is with links path.

        I tried
        href="[[~1]]


        And it always points to my default language resource.

        href="[[BabelTranslation? &resourceId=`2`]]


        It doesn't work

        What's the right way to make links for babel???

        Do i have to use different templates for each language? because i have images and some things relative to the language, like my menu images. I could use TVs but i don't have any idea of how to use it with Babel.

        Please help!

        [ed. note: juanmardila last edited this post 7 years, 10 months ago.]
        • I don't use babel, so I can't really help you on that front.

          Hopefully someone else can point you in the right direction for that.
            Patrick | Server Wrangler
            About Me: Website | TweetsMODX Hosting
          • Thanks AMDbuilder, i don't know if there's to many MODx users that uses Babel, but i will keep trying smiley
            • Hey guys, please..

              I only need how to write links within the context i'm navigating.

              Example:
              If i'm in spanish (default) and i write [[~1]] it should go to http://www.apaca.com.ve/nosotros.html
              If i'm in english context and i write [[~1]] it should go to http://www.apaca.com.ve/en/nosotros.html

              Thanks for your help.
              • Hi,

                I have the same problems with writing links on different contexts using babel and Babel.BabelTranslation. Juan, did you find a solution for your problem?

                Saludos
                • Hi hvillega,

                  I didn't find a solution, if you solve it let me know please.
                  • I do use Babel but have not used the Babeltranslation snippet, but by checking the code of it noticed that &contextKey=`` needs to be set in the snippet call, without that empty set will be returned
                      Almost retired from web-development industry but still randomly writing at Lazylegs.info and on schedule hopefully in near future to finish Oracle and PostgreSQL ports of MODX
                    • Hi i m not sure if I get it right, but i had same problem and solved it like this:

                      example:

                      <a href="[[~[[BabelTranslation? &resourceId=`3` &contextKey=`[[++cultureKey]]`]]]]">Link</a>

                      This will point you to right resource.
                      Little too late but better than nothing smiley