We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7455
    • 2,204 Posts
    I am working on a website that has 5 languages but I do not want to make 5 templates

    I made a dropdown tv called [*lang*] and made 5 options in it:

    English==1||Dutch==10||German==22||Fench==33||Italian==44

    where the number is the "root"id of the tree from that particular language

    In my template I called the MenuBuilder like this: [[MenuBuilder?id=[*lang*]]]

    now I just select the right language for the document I create and it wil always display the right menu for that language


    Greets Dimmy
      follow me on twitter: @dimmy01
    • How will you manage language files for shared objects, such as the "login" or the "contact" snippets? I find that I need to maintain the $lang variable so that I can include the desired language file in the snippets. How about links in the document’s content?
        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
        • 7455
        • 2,204 Posts
        How about links in the document’s content?
        this you will need to type in anyway in the language you need is it not?
        or do you have a translate snippet that translates all the document to another language?

        for the login and contactsnippet... I would need to translate them anyway so why not using 1 for each language?

        the $lang would be much cleaner but how do you use that when someone enters your site somewhere in the middel by a google link? how would you know at what language he enters?
        you would need some reference point could this not be set by another tv?





          follow me on twitter: @dimmy01
        • I have a snippet that sets the $lang variable in a cookie whenever one of the main language home pages/folders is entered, and a TV that takes the value from the cookie to use as the $lang variable wherever it’s needed. If somebody comes in from Google or wherever, he gets the default language site. That’s coded into the TV; no lanugage cookie, use site_start document ID; this presumes that your site_start document will be the default language home page/folder.

          I edited the login and contact snippets to use variables taken from an included language file. Then I just edit/create a new language file; no need to duplicate and rename the snippets and call a different one for each language. Just call the one, it gets the $lang variable from the TV, and loads the appropriate language file. I name the language files according to the ID of the language home page/folder; 1.php, 16.php, etc. then it’s easy to just include /assets/langs/$lang.php in the snippet. I modify the snippet to accept the $lang variable from the query string, the same as the menu snippets get it.

          here it’s in action in a site under construction

          http://www.alandaniel.co.uk/index.php?id=1

          Further discussion and the relevant snippet and TV here:

          http://modxcms.com/forums/index.php/topic,409.0.html
            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
            • 7455
            • 2,204 Posts
            Thats look briliant

            Thanks for this inside.
              follow me on twitter: @dimmy01
              • 4673
              • 577 Posts
              couldn’t you just pick up the language of the browser? Google and other sites do this. For me I hate it ! because I browse with a Japanese setting and always get bumped a lot.

              I’m still up for moving all language on the front end into the db or at the bare minimum a language file.
                Tangent-Warrior smiley
              • That would only work if by chance the user’s browser was set for one of the languages the site provides.

                I hate the Google business as well; apparently it thinks because I’m coming from an Israeli IP block I must want the Hebrew version, so I have to let it set the cookies when I select "Google in English" so I can get to the .com site, and not the .co.il site. I know it has nothing to do with browser settings, because I don’t even have Hebrew as an option, let alone the default or primary option.
                  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
                  • 34162
                  • 1 Posts
                  same here but it is based on ip block because I use anonymous proxy since my isp is so horrible i get dns request errors and page timeout if I don’t use a proxy. A s the proxy bumps me around to different locations I get google pages in french, japanese, german, spanish and whatever other countries my proxy is coming out of for that day. I really hate it.
                    • 34162
                    • 1 Posts
                    sottwell: They have to do that, I think, or at least try to-- certain countries have sued Google that they aren’t properly "cleansing" the results with their approved political slant. In order to ensure that someone in China or any of these other countries get the results that keep their governments happy (and Google in business), they began sending everyone to country-specific versions when the IP is detected to not be in the US.
                    • I wan’t exactly complaining; I know the vast majority of people coming from this IP block do want it in Hebrew. Just it’s not something I want my sites to be presuming. (and on a personal level it is a bit annoying, like trying to unscrew a screw that some idiot MALE tech screwed down so tight I can’t budge it! As if computer cases need to be bolted down like the head gasket on a car engine!)
                        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