We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10378
    • 375 Posts
    (Warning: long post!)
    I have very special questions regarding i18n and maybe you have an idea:

    I generally don't need to have a fully translated website. Some Resources needs to be in English (the MODX projects and some of the Blog entries or Tutorials) and the rest in German language. This should all be possible with only 1 context.

    So I've written a plugin which loads lexicon files depending on the browser language.
    The strings for the Templates and Chunks of the website are now provided by the lexicon files. The rest comes from the Resources.

    This works fine with some caveats (especially the MODX caching is a problem here).


    The plugin loads the appropriate lexicon + sets a placeholder with "de" or "en":

    switch ($browserLanguage) {
        case 'de':
            $modx->lexicon->load('de:site:default');
            $modx->setPlaceholder('browserLanguage', 'de');
            break;
        default:
            $modx->lexicon->load('en:site:default');
            $modx->setPlaceholder('browserLanguage', 'en');
    }



    The lexicon tags I use in chunks and Templates:

    [[!%site.title_mainmenu? &language=`[[+browserLanguage]]`]]



    1) The fist problem is, that all chunks which contains lexicon tags needs to be uncached - otherwise they will display the language of the first visitor.

    2) The second problem is that the lexicon tags doesn't work without the &language parameter as they should.

    Do you have any other idea on how to solve this in a better way?
    Do I realy need 2 Contexts?

    3) And what's about the Articles container for my Blog entries? How do I handle those in 2 Contexts?

    Greetings,
    Martin
      Freelancer @bitego http://www.bitego.com
      ---
      GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
      More infos here: http://www.bitego.com/extras/goodnews/
      • 4172
      • 5,888 Posts
      you may have a look at how migxMultiLang handles the setting of the cultureKey with a plugin and how it does the caching for each language, if not migxMultiLang would be a solution at all for this.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!