We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29796
    • 91 Posts
    i have to create multiple websites and each site will have multiple languages. I have an idea how to do it, but i have some problems ...

    for example ... i have three sub-domains now for testing

    xxx.something.com
    yyy.something.com
    abc.something.com

    i created six context nammed:
    "xxx-en, xxx-si, yyy-en, yyy-si, abc-en, abc-si"

    so two different languages for each site... on context settings i defined base_url, http_hosts, site_url, error_page, site_start and cultureKey

    in all context i inserted some resources, so the modx is ready for testing. To show right context on speciffic domain i used simple switch function in index.php, now i have more complex site, so i created plugin with onHandleRequest event for switching context.

    in my plugin for testing i only inserted this piece of code
    if($_GET[’x’]){ $modx->switchContext(’YYY-si’); } and on my homepage i created a link with [[~2]]?x=1 (2 is id of main resource on YYY-en context) .. all works fine but if i try to navigate somewhere else i get an error because context is changed to default one YYY-en instead of keeping YYY-si

    i guess that the switch in index.php changes to default context each time the page is refreshed ... how can i solve this ? ..

      • 18373 ☆ A M B ☆
      • 3,141 Posts
      I’ve not did this myself before, but am just throwing some MODx logic towards this in the hope it helps.

      First of all. You know have a switch statement in the index.php, AND a request handling plugin? That sounds like it is going to conflict either way. Simplicity is more, so drop one. My advice would be the switch statement in index.php, as that will be overwritten on update.

      You have six sites.. so first find a way to determine which one you’re on. For the first division in three that’s easy - just look at the (sub) domain being requested. The second diversion may be tougher... Some ideas:
      - If you give your users a choice on their (first) visit you could set it in a cookie or session, and check that value to see what language (and thus: context) to present. Check on *every* page if there is a cookie/session set which determines the context, or you’ll end up sending people who enter through a search engine or direct link to a 404 or wrong page.
      - A root directory (yyy.domain.com/si vs yyy.domain.com/en) to determine the language to serve. This also has the benefit of no conflicting content on the same URL, and it is easier to present users from google or a direct link the right content.


      I think that if you follow the above, you will solve your problem, as there is a persistent way of locating what language to serve. Be it a cookie or session variable, or the root dir being served. In your example, you look at a get variable which is not being appended to other links (I’m guessing) thus it is not changing to (or in better terminology initiating) the right context.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 21838
        • 284 Posts
          MODX Free Template Base: MODX-Boilerplate | my blog (lots of MODX stuff) | my gitHub (translations) | MODX User Groups Germany (Facebook)
          • 29796
          • 91 Posts
          Mark H. thanx for the tips .. i will remove switch option in index and use a plugin to switch context .. i think i will use sub dir en / si / it to show right context ...

          smooth-graphics => ... yea i looked at babel, but i rather to do and use my own solution, so if something goes wrong i know how and where to fix it ... i had problems with some allready made solutions in evo. I have to test it first, but i don’t have time to do it now... maybe in next project smiley