We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36747
    • 138 Posts
    Is team trying to add multilingual support to MODx? Or this is not part of the roadmap.

    cheers
    emiliano
      patagonia, argentina
      • 18397
      • 3,250 Posts
      It already is...
        • 36747
        • 138 Posts
        come on, i had a multilingual site running modx and had to create content as if they where pages of the same languague.. I created 2 folders, one for english pages and the other for spanish pages, but what about snippets and other things... the only way is to duplicate them.. and that’s not the best way to support multilingual sites!

        cheers
        emiliano
          patagonia, argentina
          • 18397
          • 3,250 Posts
          You can use Susan’s (sottwell) method with cookies/url strings and have your snippets pull that data to determine what strings to display.
            • 36747
            • 138 Posts
            Mark, I just wanted to know if multilingual support will be part of the core of MODx. I know that there are several hacks to achieve this (as Susan showed us), but being part of the core will help people creating multilingual sites.

            Cheers
            Emiliano
              patagonia, argentina
              • 18397
              • 3,250 Posts
              Sorry emi for my lack of an adequate response. I will look into this come Monday as I have had a very long weekend and haven’t really had the chance to read through this thread.
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                Quote from: emi at Oct 23, 2005, 10:05 PM

                come on, i had a multilingual site running modx and had to create content as if they where pages of the same languague.. I created 2 folders, one for english pages and the other for spanish pages, but what about snippets and other things... the only way is to duplicate them.. and that’s not the best way to support multilingual sites!

                cheers
                emiliano

                Not at all.

                It did require some hacking of the snippets that I wanted to use, to have them use a variable string instead of hard-coded text output. (you could set it up to use constants instead, if you prefer)

                Then I created language files which I named after the ID of the home page for that language (1.php, 2.php, etc) and used the TV to pick up the $lang variable either from the user cookie or the URL query string.

                I found it easiest to add the parameter to the snippet call and add a line in the snippet:
                [!MultilangSnippet?lang=[*getLang*]!]
                
                $lang=isset($lang) ? $lang : $modx->config['site_start'];
                include 'assets/snippets/MultilangSnippet/langs/$lang.php";
                

                to gather the value, then the snippet includes the appropriate language file.

                This way, if a language is not passed to the snippet, it will use the site_start document ID, which presumably is the home page for the default language. Of course, this means that you must have at least a language file named after the ID of the default language’s home page.
                  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
                  • 21301
                  • 93 Posts
                  I think multilingual support should become part of the core as a default module/plugin. Here’s how I’ve added this quickly for now. Just another way of doing the same without cookies.

                  Have a tree for each language and have an unpublished folder ’Menu’ for the menu in the language folder. Like this:
                  > English
                  | > Menu (unpublished)
                  | | > Home
                  | | > Feedback
                  | | > ...
                  | > Links
                  | | > Link to an english item
                  | | > ...
                  > Dutch
                  | > Menu (unpublished)
                  | | > Home
                  | | > Reageer
                  | | > ...
                  | > Links
                  | | > Link to a dutch item
                  | | > ...

                  Remove all the content from your snippets and move them to chunks. You can then use the snippets ’getLanguageId’ and ’getMenuId’ (see below) to do this:

                  Display the menu for a language.
                  [!ListMenu?LM_node=[[getMenuId]] !]
                  


                  Use a chunk in a certain language
                  {{html_navigation_[[getLanguageId]]}}
                  

                  Or wink
                  {{[[getLanguageId]]_navigation}}
                  


                  SNIPPET getLanguageId
                  return getRootId($modx);
                  
                  function getRootId($modx) {
                    $parentId=$modx->documentObject['id'];
                    do {
                      $thisId=$parentId;
                      // Get published or unpublished parent
                      $thisDoc=$modx->getDocument($thisId,'parent',1,0) ? $modx->getDocument($thisId,'parent',1,0) : $modx->getDocument($thisId,'parent',0,0);
                      $parentId = $thisDoc['parent'];
                    } while ($parentId!=0);
                    return $thisId;
                  }
                  


                  SNIPPET getMenuId
                  // First get the root ID for this branch
                  $pId = getRootId($modx);
                  
                  // Next, get all children for this parent
                  $children = $modx->getDocumentChildren($pId, $published=0, $deleted=0, $fields="*");
                  
                  // Then find the child named 'Menu'
                  $i=0;
                  while ($children[$i]['pagetitle']!="Menu" || $i>=count($children)) $i++;
                  
                  return $children[$i]['id'];
                  
                  function getRootId($modx) {
                    $parentId=$modx->documentObject['id'];
                    do {
                      $thisId=$parentId;
                      // Get published or unpublished parent
                      $thisDoc=$modx->getDocument($thisId,'parent',1,0) ? $modx->getDocument($thisId,'parent',1,0) : $modx->getDocument($thisId,'parent',0,0);
                      $parentId = $thisDoc['parent'];
                    } while ($parentId!=0);
                    return $thisId;
                  }
                  
                    • 25663 MODX Staff
                    • 12,272 Posts
                    The more I think about this, the more I’d like to move languages to the database per reporta’s original suggestion. It makes "inline translation" much more simple than creating extra files on the filesystem, etc. We should be able to import from translation files though, I think. wink

                    This way, the page content could also be easily translated and substituted as needed for the languages you turn on in the manager.
                      Ryan Thrash, MODX Co-Founder
                      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                      • 6726
                      • 7,075 Posts
                      That would be great !

                      Inline translation is cool indeed, and for multi-lingual websites it would definitely be a huge helper smiley

                      Quote from: rthrash at Nov 17, 2005, 09:29 AM

                      The more I think about this, the more I’d like to move languages to the database per reporta’s original suggestion. (...)
                        .: COO - Commerce Guys - Community Driven Innovation :.


                        MODx est l'outil id