We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    I’ve never actually done a multi-language site so I’m talking out of my butt here. wink

    Personally, I don’t think I’d use the JS solution because it’s a waste of bandwidth and would slow page loading. I’d be more inclined to put each language in it’s own chunk, named with the pagetitle+language, then use a snippet or plugin to pull in the appropriate chunk.
      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
      • 29774
      • 386 Posts
      @PMS, your module sounds fantastic! By all means use anything you like from my implementation.

      I started with the same goal of not having to alter existing templates, but quickly ran into the problem of how to access fields nested inside chunks rather than in the main template. I wasn’t able to find a system event at which the chunks had been retrieved but not parsed; I concluded that it wasn’t possible without parsing the chunks yourself with modx->parseChunk, but realised I’d need to make this recursive for chunks nested inside chunks nested inside chunks... - and that’s where I gave up, since I’d essentially be replicating what the modx parser does. This is why I ended up using a general purpose snippet instead, so I can replace any field in any template or chunk with either:
      [!Translate? &tpl=`MyChunk`!]
      or
      [!Translate? &field=`myField`!]

      Did you solve this problem, or will all fields need to be exposed in the main template?

      I’ve realised that it should be possible to improve the Translate snippet so that it outputs all translations into the cache (perhaps as a serialised array since this is how the modx cache works) and then it would check the cache before querying the db and set a global array of placeholders with a reference to the desired language (since in some cases the field/chunk should fall back to the default language). This array would then be used by the LanguageSwitcher plugin to alter the modx->documentOutput accordingly.

      I’ve also been playing with ManagerManager as a way to organise the translated fields into tabs within the Manager, it would be fairly easy to generate the relevant rules with an include in mm_rules.inc.php:



      @BobRay - I think the wiki may be right in the sense that caching happens after OnWebPagePrerender fires, however I think it is $modx->documentContent that gets cached not
      $modx->documentOutput.




        Snippets: GoogleMap | FileDetails | Related Plugin: SSL
        • 22851
        • 805 Posts
        My module (called YAMS - Yet Another Multiligual Solution) has got several components, the third of which does what you were asking:
        • A module, which allows you to configure the languages and how you get redirected from the old non-multilingual pages to the new multilingual ones.
        • A plugin, which does most of the hard work for you automatically, like replacing document variables by the appropriate language content and parsing special yams placeholders that provide access to the current language etc.
        • A snippet that allows more advanced usage. For example, it allows you to choose between a list of chunks, tvs, document variables or placeholders dependent on the language, so that you can customise the format dependent on the language if you like. It also allows you to output a list or drop down so that you can choose the current language (which will be templatable). You can also use this snippet within ditto style templates to include multi-language equivalents of the normal placeholders.
        • Extensions or modified templates for the main MODx resources (ditto and wayfinder only so far)
          YAMS: Yet Another Multilingual Solution for MODx
          YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
          Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
          • 22851
          • 805 Posts
          therebechips. My solution does work with chunks. I can confirm that because my document templates are a maze of nested chunks and I haven’t encountered any problems. I expand out my document variables into their multilanguage versions on the OnParseDocument event. I then select the appropriate language on the OnWebPagePrerender event.
            YAMS: Yet Another Multilingual Solution for MODx
            YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
            Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
            • 22851
            • 805 Posts
            By the way. I also tried using ManagerManager to put template variables for individual languages on different tabs - but I seemed to encounter some bug within ManagerManager which prevented that from working properly. I haven’t reported it yet though.
              YAMS: Yet Another Multilingual Solution for MODx
              YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
              Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
              • 17883
              • 1,039 Posts
              Go on PMS, this sounds great! Is your code above ready for testing? Or should I wait until you finished your modules?
                • 22851
                • 805 Posts
                It’s *almost* there. I have a basic working version, but there are a few changes I want to make so that I will be able to incorporate more features later, so it’s not quite stable yet. I’m not going to be able to work on it this weekend much (my sister’s 30th birthday), but hopefully should have a beta version for testing the weekend after or shortly after that. I think it would be worth spending some time documenting it properly too. So, please be patient, it’s on the way.
                  YAMS: Yet Another Multilingual Solution for MODx
                  YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
                  Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
                  • 17883
                  • 1,039 Posts
                  Thanks a lot. No hurry ;-)
                    • 29774
                    • 386 Posts

                    I also tried using ManagerManager to put template variables for individual languages on different tabs - but I seemed to encounter some bug within ManagerManager which prevented that from working properly. I haven’t reported it yet though.
                    Was it the bug where TVs with underscores don’t get selected? eg, myTV_de, myTV_fr - the workaround is to remove the underscore from your TV names smiley


                    My solution does work with chunks. I can confirm that because my document templates are a maze of nested chunks and I haven’t encountered any problems. I expand out my document variables into their multilanguage versions on the OnParseDocument event. I then select the appropriate language on the OnWebPagePrerender event.
                    Brilliant!
                      Snippets: GoogleMap | FileDetails | Related Plugin: SSL
                      • 22851
                      • 805 Posts
                      Yes. It is the underscore bug. It’s built into my solution at the moment, but it should be very easy to change. I think the problem arises because MODx urlencodes the tv names at some stage, so ManagerManager is trying to compare against a version where the underscore has been replaced by a %.. code. Do you know if a dash - or some other character would work instead?
                        YAMS: Yet Another Multilingual Solution for MODx
                        YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
                        Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.