<![CDATA[ How to create a multilingual site (with front-end language switch)? - My Forums]]> https://forums.modx.com/thread/?thread=104010 <![CDATA[How to create a multilingual site (with front-end language switch)?]]> https://forums.modx.com/thread/104010/how-to-create-a-multilingual-site-with-front-end-language-switch#dis-post-559352 I've tried googling this, but I feel like I'm not familiar enough with modx and its terminology to really understand the search results. Hopefully some of you can tell me if what I'm looking for is possible. (Also, I haven't gotten around to installing modx yet due to hosting issues, so please excuse the vagueness.)

I'd like to build a site where there is a front-end langauge switch (like an English and a Danish flag in the upper right corner e.g.). I've read something about the lexicon, which I assume I could use to change the menues and such?
But how do I make it so that, when the user creates a new post (document) in the manager, there'll be both a Danish and an English content field (preferably right next to or below eachother)? I'm not looking for an automatic translation, but instead the option to write our own translation as well as being able to post different things depending on language chosen (since not everything is relevant to non-Danish speakers).

Is there any extras that does this (and if so, which ones)?]]>
wyrdling Jul 05, 2018, 01:54 PM https://forums.modx.com/thread/104010/how-to-create-a-multilingual-site-with-front-end-language-switch#dis-post-559352
<![CDATA[Re: How to create a multilingual site (with front-end language switch)?]]> https://forums.modx.com/thread/104010/how-to-create-a-multilingual-site-with-front-end-language-switch#dis-post-559425
That would work best like this:

$defaultLanguage = 'en'; // or 'dk'
$lang = $modx->getOption('site_language', $_SESSION, $defaultLanguage, true); 


Using getOption() this way handles the cases where the $_SESSION variable is not set or is empty. In both cases, the default language will be set.

BTW, that whole plan of mine above was off the top of my head late at night, so I can't guarantee that it will all work. wink]]>
BobRay Jul 08, 2018, 10:18 PM https://forums.modx.com/thread/104010/how-to-create-a-multilingual-site-with-front-end-language-switch#dis-post-559425
<![CDATA[Re: How to create a multilingual site (with front-end language switch)?]]> https://forums.modx.com/thread/104010/how-to-create-a-multilingual-site-with-front-end-language-switch#dis-post-559416 nuan88 Jul 08, 2018, 06:20 PM https://forums.modx.com/thread/104010/how-to-create-a-multilingual-site-with-front-end-language-switch#dis-post-559416 <![CDATA[Re: How to create a multilingual site (with front-end language switch)?]]> https://forums.modx.com/thread/104010/how-to-create-a-multilingual-site-with-front-end-language-switch#dis-post-559405
Edit: What if I create a TV for the English bit and then create a snippet that displays either the regular resource content -or- the info in the TV (depending on the chosen language). Could something that simple might work?]]>
wyrdling Jul 08, 2018, 12:55 PM https://forums.modx.com/thread/104010/how-to-create-a-multilingual-site-with-front-end-language-switch#dis-post-559405
<![CDATA[Re: How to create a multilingual site (with front-end language switch)?]]> https://forums.modx.com/thread/104010/how-to-create-a-multilingual-site-with-front-end-language-switch#dis-post-559381
Having only two languages makes it easier. Personally, I would avoid using multiple contexts for this.

I think I would set this up with the Resource 'content' field your primary language and a Template Variable (TV) for the secondary language. It might be easier to let the users create the posts in NewsPublisher in the front end. That would make it easy to show the two text areas one above the other, leave out fields you don't care about, and let you set the captions for each textarea.

Assuming that the TV is named "secondaryLanguage" -- this is one way to do it:

Create two System Settings with these keys: primary_language, secondary_language and either en or dk for the values.
Create a namespace called multilang with a core path of {core_path}components/multilang/
Create a directory in the core/components/ directory called multilang

Where the content will be displayed on the page, put this in the template:

<div class="content_div">
    [[!ShowContent]]
</div>

Then create a snippet called "ShowContent with this code:
/* ShowContent snippet */


$primaryLanguage = $modx->getOption('primary_language');
$secondaryLanguage $modx->getOption('secondary_language');

$lang = $modx->getOption('site_language', $_SESSION, $primaryLanguage, true];

if ($lang == $primaryLanguage) {
    $output = '[[*content]]';
    $modx->lexicon->load($primaryLanguage .  . ':multilang:default');
} else {
    $output = '[[*secondaryLangauge']]';
    $modx->lexicon->load($secondaryLanguage . ':multilang:default');
}
return $output;


The lexicon->load() line is to load language strings for other parts of the page or template that should be in a particular language. Use language tags for them and create two lexicon files containing the values. The two files would both be called default.inc.php and would be in the en and dk directories under core/components/multilang/lexicon.

core
   components
      multilang
         lexicon
            en
              default.inc.php
            dk
              default.inc.php


Your two language selection buttons can input buttons for forms that submit to the current page and contain a hidden input that sets the language. You'll need a snippet at the top of the body section that sets the 'site_language' $_SESSION variable to the value submitted in the form.

$_SESSION['site_language'] = 'en';
or
$_SESSION['site_language'] = 'dk';


If your users log in, you could set a user setting in that snippet with the key 'site_language' and modify the code of the ShowContent snippet to use that if it exists.

If this sounds like too much for you, check out MigxMultilang (MML). Here are the official docs for it: https://github.com/Bruno17/migxmultilang. From what I read, MML is very robust. It creates multiple TVs for you (one for each language) and embeds the two-letter language code in the URL. I'm not sure it would handle creating user settings for you, but if users don't log in, they won't work anyway -- and as long as the users come in on the correct URL (e.g., yoursite.com/dk/somepage) the'll get the correct language.

]]>
BobRay Jul 07, 2018, 05:04 AM https://forums.modx.com/thread/104010/how-to-create-a-multilingual-site-with-front-end-language-switch#dis-post-559381
<![CDATA[Re: How to create a multilingual site (with front-end language switch)?]]> https://forums.modx.com/thread/104010/how-to-create-a-multilingual-site-with-front-end-language-switch#dis-post-559368
I have made two identical sites in different languages before, and its important when you get started that you make the collation of your database utf-8, otherwise problems could/will arise]]>
nuan88 Jul 06, 2018, 11:12 AM https://forums.modx.com/thread/104010/how-to-create-a-multilingual-site-with-front-end-language-switch#dis-post-559368
<![CDATA[Re: How to create a multilingual site (with front-end language switch)?]]> https://forums.modx.com/thread/104010/how-to-create-a-multilingual-site-with-front-end-language-switch#dis-post-559367
You can also setup multiple contexts to handle different languges (lookg at XRouting extra) but that would require creating essentially two different sites as new resources/posts aren't automatically carried over to the other context(s).
]]>
lkfranklin Jul 06, 2018, 09:53 AM https://forums.modx.com/thread/104010/how-to-create-a-multilingual-site-with-front-end-language-switch#dis-post-559367