We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3785
    • 143 Posts
    I just finished the multilingual website http://www.ab-m.de for a customer of mine and wanted to share my solution for a multilanguage site:

    I made a variant of the "Make Multi Lingual Site" How To found on http://wiki.modxcms.com/index.php/Make_Multi_Lingual_Site.

    First thing: my Document Tree looks like this (see attached image).
    This way I can get the language by:
    // getLang snippet
    $ultimateParentID=$modx->runSnippet("UltimateParent");
    $ultimateParent=$modx->getDocument($ultimateParentID);
    return($ultimateParent["alias"]);
    

    A language array is created by:
    // print languages snippet
    $langArray=$modx->getDocumentChildren(0);
    foreach($langArray as $language)
    {	
    	$langHomeURL=$modx->makeUrl(intval($language["id"]));	
    	echo('<a href="'.$langHomeURL.'">'.$language["pagetitle"].'</a>');
    }
    

    Navigation is build by:
    [!Wayfinder? &startId=`[[UltimateParent]]`!]
    

    Second thing: I made an summary of all relevant document IDs:
    $home["de"]=1;
    $home["en"]=32;
    
    $context["de"]=11;
    $context["en"]=53;
    
    $metaTags["de"]=57;
    $metaTags["en"]=56;
    
    $metaNav["de"]=7;
    $metaNav["en"]=49;
    ...
    

    Setting this IDs allows me later on to get the desired documents without bothering what language is selected.
    Examples:
    $modx->setPlaceholder('homeURL', $modx->makeUrl(intval($home[$lang])));
    ...
    $modx->setPlaceholder('aktuellesID', $aktuelles[$lang]);
    ...
    

    or
    [!Ditto? &tpl=`dittoAktuelles` &startID=`[+aktuellesID+]`!]
    

    Of course there are a few more things to take care of so that the multi lingual site runs smoothly. But these are the most important steps.

    I hope this helps you smiley
      Medianotions – Studio für Webdesign
      http://www.medianotions.de
      • 19257
      • 141 Posts
      This is awesome, I’ll give it a try!
        • 32646
        • 87 Posts
        Looks interesting.

        My biggest problem is the docid’s being all over the place. Your listing of the relevant relationships helps:
        $home["de"]=1;
        $home["en"]=32;
        
        $context["de"]=11;
        $context["en"]=53;


        But that got me thinking. Maybe we can add a metacode (maybe TV?) that would link them so Home code would be `1` and About Us would be `5`, etc. Then to navigate to a new language, just go to the right UltimateParent and then navigate down to the right TV code. Does that make sense? Would it work?

        I just want to avoid having to write:

        en=241,es=242,nl=529,ru=358,zh=415


        for every single page. All my language folders are still empty, haven’t gotten the translated yet.
          Just learning the ropes.
          • 3785
          • 143 Posts
          I just want to avoid having to write
          en=241,es=242,nl=529,ru=358,zh=415
          for every single page.

          No, you misunderstood. You don’t have to write down the IDs of every page. Just the ones that are relevant for the template. For example the Home site. You need to know where it is in the different languages so that easily link to it. So you define:
          $home["de"]=1;
          $home["en"]=32;
          

          Write this to a placeholder:
          modx->setPlaceholder('homeURL', $modx->makeUrl(intval($home[$lang])));

          … and can use this in your template oder the site content:
          <a href="[homeURL]">Back to Home</a>

          This method is also useful for parts of your site like the sidebar, the footer and so on so you don’t have to build a different template for each language.

            Medianotions – Studio für Webdesign
            http://www.medianotions.de
            • 32646
            • 87 Posts
            But how do you go from a description page of a product deep in the German folder to the same page in English?

            I understand you now you are talking about the navigation and header and footer and things like that.
              Just learning the ropes.
              • 3785
              • 143 Posts
              But how do you go from a description page of a product deep in the German folder to the same page in English?
              That is not directly possible with this solution. I don’t think this is a big issue, because website visitors usually don’t switch the language very often. It is more the developer or the translator who needs this feature, but they can work with different browser tabs or windows.

              If you really need this feature you could use friendly URLs to accomplish this if you use the same alias in both languages:
              mysite.com/de/category-10/product-4/variant-17.html
              mysite.com/en/category-10/product-4/variant-17.html
              

              Then you only have to change the language indicator in the URI.
                Medianotions – Studio für Webdesign
                http://www.medianotions.de
                • 32646
                • 87 Posts
                Yes, that’s true. That would be another way to do it.

                I haven’t even gotten into having different headers and graphics for the different languages. I’ll take a closer look at your solution for that when I get there.

                Thanks
                  Just learning the ropes.