Multi Lang another approach

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
brownrl
Forum Members
Forum Members
Posts: 74
Joined: Thu Sep 23, 2004 11:06 am

Multi Lang another approach

Post by brownrl »

So I have been using CMS for sometime here in Belgium where Dutch and French are both official languages. I have some .9 versions still installed at some places. Greatest CMS EVER!

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;
	}
}
So now anytime I need the language I can reference $_SESSION['lang'] or ... {lang} see next bit;

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" />
or if I am processing a form in PHP somewhere:

Code: Select all

$this->Redirect("index.php?page=something-".$_SESSION['lang']."");
As I mentioned not perfect. The only real draw back is that admining content in the back end becomes cumbersome for large sites. Then again all large sites require cumbersome content admining.

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.
User avatar
manuel
Power Poster
Power Poster
Posts: 353
Joined: Fri Nov 30, 2007 9:15 am

Re: Multi Lang another approach

Post by manuel »

Hi Brownrl,

Until now, i've been using the following methods:
- using the "page alias" to redirect users to the correct page when switching language
http://forum.cmsmadesimple.org/viewtopi ... =4&t=48112

- using the "hierarchy position" to redirect users to the correct page when switching language
http://www.i-do-this.com/blog/25/Anothe ... CMSMS-Page

But... I'm especially looking forward to the new 1.10 release wich will make it possible for a more advanced multi language module to be developped!!
- Add more events to allow for a proper multi-language addon module
http://forum.cmsmadesimple.org/viewtopi ... =1&t=54021

Greetings,
Manuel
Post Reply

Return to “Tips and Tricks”