Every site that I touch needs to be in both NL and FR and sometimes in a third with English or German.
I too once used the MLE fork. Promising but quirky and ultimately not maintainable.
Here is what I have come to over the years. I wish to share it and see what the community thinks. This is basically my technique cobbled together with some plugins, common sense, testing, playing, it's not perfect but clients are using it happily and more importantly paying for it. Scroll down for coding bits...
Conditions:
1) Multi Tree
1 branch for FR
1 branch for NL
1 branch for ...
A single tree approach just poses too many problems that multi tree approach solves, although a multi tree approach creates another set of problems. The multi tree approach will allow separate titles, menu texts, contents, meta tags, extra infos, thumbnails, ... This also means the FR pages can use the FR Template and NL the NL template, or all languages share a template and use programming.
When you see the second part you should realize the tree structure is NOT so important, just helps when doing admin work.
The single tree approach does lessen some of the administration work and cleans up the job of editing and managing content, but forces special programming and handling. Hence the MLE fork. I think with some standardization in the admin, CMS MS could use the Multi tree solution and have it look and behave like a single tree solution.
My suggestion to the CMS MS people is to also make a 'language header' sorta like the 'section header' content type and go from there. If a page is under a language header its considered to be 'xx' language page.
For the most part clients understand that they need to or should try to keep the structure in NL the same as FR. However, with the next part you will see that it is not 100% critical. If the tree structure is not perfect the only real problem is the doing content work gets trickier, NOT my problem per say and not the end of the world.
2) Use the page aliases
All pages in all languages must have -xx, where -xx is the lower case iso 2 letter representation of the language, -fr -nl -en ...
The user can hot switch the language and stay on the same page.
?page=view_products-fr links to -> ?page=view_products-nl
If you need clean urls, then you either link to the top of the site in other languages, or make a plugin to retrieve the alias of the page with same hierarchy. ( 2.3.4.5 -> 3.3.4.5 )...
When it comes to clean urls, mod_rewrite and .htaccess allow for 100000 combinations that I am not going to get into. I just normally keep my aliases as a rune stone in english.
My users thankfully understand the basic rune stone concept and that all pages must have a -xx on the end of the alias. I turn off the auto aliasing in the config, so that anytime a user makes a new page, they have to set the alias manually. From time to time users will forget -fr or -nl but not the end of the world either.
The nice part about this method is that it does not require huge amount of programming to the core of CMS MS and nor does it required admin users to be overly tech inclined. Just aware.
Coding Bits:
1) Use a bit of code at the top of all templates to set a session variable. I put this in a plugin and then put it at the top of all templates that need language.
I copied the snippet of code to get the alias and preg the language based on the alias of the current page. So it works with clean urls, alternate aliases urls, or ugly urls.
Code: Select all
function smarty_cms_function_setLang($params, &$smarty)
{
global $gCms;
$pageinfo = &$gCms->variables['pageinfo'];
$config = &$gCms->config;
if (isset($pageinfo) && $pageinfo->content_id == -1)
{
#If you have a custom error message... set a message
}
else
{
$result = $pageinfo->content_alias;
if (!(isset($config["use_smarty_php_tags"]) && $config["use_smarty_php_tags"] == true))
{
$result = ereg_replace("\{\/?php\}", "", $result);
}
if( preg_match( "/-..$/" , $result ) )
{
$result = preg_replace( "/^.*-/" , "" , $result );
}
else
{
$result = "--";
}
$_SESSION['lang'] = $result;
}
}
Code: Select all
function smarty_cms_function_lang($params, &$smarty)
{
return $_SESSION['lang'];
}
In a template or page or wherever i can do some fun stuff like this:
Code: Select all
<img src="uploads/images-{lang}/header.png" />
Code: Select all
$this->Redirect("index.php?page=something-".$_SESSION['lang']."");
I would like to see some day a new type of content in the CMS MS:
'Language Header' sort of like the Section Header. $_SESSION['lang'] or $_SESSION[language'] always gets set to whatever the closest 'language header' up the hierarchy is.
I also pair this with a module called 'Texts' for handling small pieces of text that I don't want to program into the smarty template. More on this in another post.
I honestly believe that the solution to Multi Language is much simpler than some people think. With a few tweaks here and there I am sure CMS MS can handle it in the admin. For now I hope this helps.