We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16905
    • 46 Posts
    Hi,
    I am new to MODx and html actually all together, I am more of a designer. Anyway, I am trying to learn ’cause you gotta start somewhere. I actually have my site up and running in English, and I have all my pages designed any waiting for their translations on the Swedish part.

    I found the article Make Multi-Lingual Site on Wiki - http://wiki.modxcms.com/index.php/Make_Multi_Lingual_Site
    Not really being 100% at code, I am feeling rather clueless.
    When reading the article, I understand the steps themselves, just not the two most important, the Languages and Redirect sections, I am not sure what information to type in where the author has written in red. The only one I get is the ’$langnames = array(’ part.

    I really want to learn this. Can someone please help me and give me a "Make_Multi_Lingual_Site for absolute dummies"??

    Thanks,
    Leigh

    Redirect

    Create a new snippet, call it "Redirect" and put the following code inside it:

    <?php
    $url = $modx->makeUrl($id);
    ob_end_clean(); // this will end the output buffer and discard silently what ever was in it
    header(’Location: ’.$url);
    ?>


    Languages

    Create another snippet called "Languages" with the following code:

    <?php
    // get languages info
    $tv = $modx->getTemplateVar(’languages’, "", $modx->documentIdentifier);
    $languages = $tv[’value’];

    if (!strlen($languages))
    {
    return "";
    }

    $langnames = array(
    "en" => "English",
    "se" => "svenska"
    );

    $output = "";

    // get entries in languages list
    $entries = explode(",", $languages);
    // loop through language entries
    for ($e = 0; $e < count($entries); $e++)
    {
    // seperate into lang code and target document id
    list($lang, $targetid) = explode("=", $entries[$e]);
    $image = ’<img src="assets/images/’.$lang.’.gif" width="16" height="11" border="0" alt="’.$langnames[$lang].’" />’;
    if (strlen($output))
    {
    $output .= ’ ’;
    }
    $output .= ’<a href="’.$modx->makeUrl($targetid).’">’.$image.’</a>’;
    }

    return $output;
    ?>
      • 20289
      • 958 Posts
      Location: is the [~id~] of a page that you want the translated version of your page to be.
      $image variable is some kind of icon that represents the language iso code, something like small flag of country of targeted language.
      You need to duplicate the original page/document to be used as of redirection target of the original page, As you need to define the translated page of each and every original language document/page, You need to manually do the change to the [~id~] of each page that has the translation or either by using a template variable to do so.

      For each page on your site you need to specify which is the translated page. This is achieved using the languages template variable. The format of the template variable value is:
      two_letter_iso_country_code=document_id,two_letter_iso_country_code=document_id
      Here are some examples:
      de=3
      specifies that the Deutsch version of this page has the ID 3.
      en=2,pl=6,fr=7
      specifies that the English version of this page has the ID 2, the Polish version of this page has the ID 6 and the French version of this page has the ID 7.
      I move this topic to the internationalization subforum.
        [img]http://i10.tinypic.com/52c4eir.gif[/img][/td]
        [td][Wiki] [Persian support forum]
        [SVN] [RTL SVN Branch] [bugs] [FishEye+Crucible] [Learn MODx!] | [My Google Code]
        [font=tahoma][برای دسترسی به راهنمای فارسی به [url=http://www.modxcms.ir]
        • 32646
        • 87 Posts
        You can ignore that. The only thing you have to change is the language array, which you already did. And also make sure your flag gifs are in the images directory.

        I just finished doing this for the first time last week.

        Eric
          Just learning the ropes.
          • 16905
          • 46 Posts
          Thanks to you both for helping.

          It is just too cool! I got it working. smiley
            • 16905
            • 46 Posts
            Hi Eric,
            I think I got prematurely excited. smiley I got everything working, but how and where do I plug in the Redirect snippet?

            Help much apreciated.
            Leigh
              • 32646
              • 87 Posts
              If you are creating an empty container for each language, you should put the redirect in that container and also on the website homepage.

              en (container)
              --Home (English homepage docid[5])
              --other subfolders (English)
              se (container)
              --Home (Swedish homepage docid[100])
              --other subfolders (Swedish)

              So on the se container you would insert [!Redirect?id=`100`!] and the same thing on the default homepage. Then on the English homepage you would insert [!Redirect?id=`5`!]

              This is not absolutely necessary to use if your layout is different.
                Just learning the ropes.
                • 29076
                • 615 Posts
                Hmm, this is actually a little embarrassing, but how do you duplicate the hole tree into another container?
                  I think, thererfor I am! But what I am, and why...?
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  Start with one document, say "English". Set up all the pages you want on the site under that folder, that is, all of the pages that will be in English. News, About, Contact, etc... the whole site structure.

                  Now duplicate that "English" document, and all of the children of the English document are also present under the new document. Rename it to Deutsch (for example). Rename and translate the content of the documents, and your German section is done.

                  Repeat the process for as many languages as you want.

                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 32646
                    • 87 Posts
                    Just right-click on a container/folder and use the duplicate command.
                      Just learning the ropes.
                      • 29076
                      • 615 Posts
                      Thanks. It just says Duplicate document, and I never thought (I never tried) it also duplicats the hole container WITH all the underlaying documents. I thought it was only the single document that was duplicated. (Maybe the context-menu should reed Duplicate documents on containers. wink )

                      Thanks again. laugh
                        I think, thererfor I am! But what I am, and why...?