We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8522
    • 145 Posts
    Hi all
    I like the solution of http://wiki.modxcms.com/index.php/Make_Multi_Lingual_Site and tried to make a little improvement.

    start (1)
    en (2)
    |-> Welcome (3)
    de (4)
    |-> Willkommen (5)

    First remark I guess we can omit the Redirect snippet and start(1). Instead configure the modx site start directly to Welcome (3) or whatever language you want to be your default.

    Secondly (now the point why i write this topic)
    I wanted a more user friendly way to specify the pages and not "en=2,pl=6,fr=7". I think this is not really user friendly. The idea is that each language has its own drop down document list. So you can conveniently specify the documents from a list with their real titles and don’t care about id’s. Luckily i found the ddTree snippet http://modxcms.com/ddTree-dropdown-Tree-1700.html.

    Example with 2 languages (i.e. "Deutsch", "English"):

    TV’s
    Create a TV for each language name it "Deutsch", "English" and so on.
    Input Type: choose DropDown List Menu
    Input Option Values (now here you have to specify the language container i.e. 4 for German):
    @EVAL return $modx->runSnippet("ddTree",array('doc'=>4));

    Note that this TV’s need the ddTree snippet to work.

    Snippet
    This is a modified snippet based on the Languages snippet form http://wiki.modxcms.com/index.php/Make_Multi_Lingual_Site. Note for additional languages you will have to extend the langnames array. I named it [[Languages2]] but feel free.

    <?php
    // version 2.0.0
    // based on http://wiki.modxcms.com/index.php/Make_Multi_Lingual_Site
    
    $langnames = array(
      'en' => 'English',
      'de' => 'Deutsch'
      );
    
    $output = '';
    
    // get entries in language tv's
    foreach ($langnames as $lang => $long) {
      $target = $modx->getTemplateVar($long, '', $modx->documentIdentifier);
      $targetid = $target['value'];
      if (is_numeric($targetid)) {
        // $link = '<img src="assets/images/'.$lang.'.gif" width="16" height="11" border="0" alt="'.$long.'" />';
        $link = $lang;
        if (strlen($output)) {
          $output .= ' ';
        }
        $output .= '<a href="'.$modx->makeUrl($targetid).'" title="'.$long.'">'.$link.'</a>';
      }
    }
    return $output;
    ?>


    Now call the snippet [[Languages2]] in your template and specify the corresponding documents in your sites. For now, if you leave it blank the language doesn’t show up in the language list.

    Any comment and feedback appreciated. cheers eni