We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • I'm using a very simple method for multilanguage support; my root level documents are the home page for each language. I use a simple list menu snippet to create a language menu. (it would be easy to change the snippet to make a drop-down if that is preferred).

    I created a general-purpose GetLang snippet:
    $lang = isset($_GET['lang']) ? $_GET['lang'] : '1';
    return $lang;

    Language files are named after the ID of the language main document; 1.php etc, and stored in assets/langs. I created a GetLangFile snippet, although I would prefer to find a place in the core scripts where this could be done for all pages:
    if(!isset($lang) || $lang = "") $lang = 1;
    include "./assets/langs/$lang.php";

    I carry the lang preference across pages by adding a "lang=" to the query string, the lang being the document ID of the home page, as selected by the language menu.

    This meant modifying the MenuBuilder snippet a bit:
    $id = isset($id) ? $id : $_GET['lang']; //language main document
    if(!isset($id)) $id = '1';
    .
    .
    .
    <a ".$active." href='[~".$children[$x]['id']."~]&lang=".$_GET['lang']."'>

    This works fine for simple sites with no user login. To handle user login, I added the query string to the "action" of the forms in the weblogin template to pass the $_GET['lang'] variable. Then I modified assets/snippets/weblogin/weblogin.processor.inc.php:
    (line 144 - logout)
    // redirect to first authorized login page
    $url = $modx->makeURL($_GET['lang'])."&lang=".$_GET['lang'];
    
    (line 356 - login)	
    // redirect to login home page
    $url = $modx->makeURL($id)."&lang=".$_GET['lang'];

    I made the same addition to every makeURL call in the script.

    This works for carrying the chosen language across login and logout. No specific login or logout page was set for either the user or for the WebLogin snippet, it will just stay where it is on login and go to the language home page on logout. It also plays nice with Friendly URLs.
      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