For a MultiLanguage site I setup CMSMS in a specific way to have the language in the menu as first-level menu. It uses a UDT and switches to the default language of that user, showing all children (language specific pages) under that language.
My page structure looks like:
- Home
- NL
- NLpage1
- NLpage2
- EN
- Enpage1
- Enpage2
- FR
- FRpage1
- FRpage2
I created a UDT called "browserlanguage" that holds:
{
$lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
if (substr($lang, 0, 2) == 'en')
{
header("Location: index.php?page=en");
} elseif (substr($lang, 0, 2) == 'fr')
{
header("Location: index.php?page=fr");
} else {
header("Location: index.php?page=nl");
}
}
The logic of the UDT, is to retrieve the language "if (substr($lang, 0, 2) == 'en')" leads to "en" and the page to be opened is "header("Location: index.php?page=en");", where "page=en" is the alias of the page to be opened.
Content-page 'Home' has this tag in the contentpage.
Insert in the template, where you want the flags to appear for the language. page="XX", where "XX" is the language page in the menu. This is to have the ability to choose a language different than their browser or the default.
<div style="float: right;">
{cms_selflink page="en" image="uploads/flags/lang_en.gif" alt="English" imageonly=1}
{cms_selflink page="fr" image="uploads/flags/lang_fr.gif" alt="French" imageonly=1}
{cms_selflink page="nl" image="uploads/flags/lang_nl.gif" alt="Nederlands" imageonly=1}
</div>
The original {menu} needs an additional parameter (start_level) as it only has to show the children of the chosen parent,
{menu template='simple_navigation.tpl' start_level='2' collapse='1'}
By going to the site, the home-page will open, run the UDT and re-direct to the language set in the browser.
You can test this on
http://demo.krijt.eu, where the code described above is active. For users on IE, the language pulled is the language on top in "Tools -> Internet Options -> Languages".
As you all can see the default language is "NL", so for most users that have their language set to "EN", the script should bring them to the English page.
Ronny