x
 
Create New Page
 View Previous Changes    ( Last updated by yvonne m. )

multi-lingual site - an easy alternative

Category:Languages
From time to time I get questions about multi-lingual sites in response to my proposal for an easy solution to multi-lingual sites in the forums. So I thought I’d wiki it here, with a few improvements due to new features in EE.

The basics is structural and a question of mirroring. Create one weblog with a corresponding template group. Name the template group according to language codes, for instance, en or whatever you like.  Assign the weblog/field group, a category group and a status group to the template group. This is our ’first’ language.

Now, creating one weblog for each language with a corresponding template group makes it easy to add new languages as you go along. Just duplicate an existant weblog and an existant template group. Assign new names and change the path settings to the ones of the template group in the weblog preferences and the value of the global variables {my_template_group} and {master_weblog_name} in the templates to the newly created template group and weblog. And voila!

But, we have to link the languages together. To link entries we add a relationship field to the weblog form. We only have to link from the foreign language to the site’s primary language as the revers_related_entries tag catches them all when we move in to the templates for linking it all together.

Second, we need to set categories to the entries. This was my main pain in the neck but with the new category custom fields, this has been resolved. While the entire structure is built on mirroring,  category group and categories are nevertheless the same. Create a category custom field for each language and add the name of the category. Now it is easy to switch between the languages at the level of categories as well AND to display the name of the category on your page. You won’t be able to use category_url here, unless you’re happy with a monolingual or non-sensical url.

The tricky part is to write the URls that link the languages together, but it has been made a lot easier with the {page_url} variable and the category custom fields. If you have few pages that are basically static you’d link from the foreign language page to the primary one:

{exp:weblog:entries weblog=”sv” }
{related_entries id
="translation"}
<a href="{page_url}">english</a>
{/related_entries}
{
/exp:weblog:entries}

And from the primary language page to the foreign language as follows:

{exp:weblog:entries weblog=”en”}
{reverse_related_entries weblog
="sv"}
<a href="{page_url}">svenska</a>
{/reverse_related_entries}
{
/exp:weblog:entries}

And that would be it!

But life is seldom as simple as that! We will probably have to revert to several conditionals. The possiblites for what a link could look like are of course numerous, but let me give you an example. Let’s say we have an URL http://my-site/en/about_me/C43/251/, then we could write:

{exp:weblog:entries weblog=”en”}

{reverse_related_entries weblog
="sv"}

{if segment 2
==”about_me”}
<a >svenska</a>

{if:else}

<a href="{page_url}">svenska</a>
{/if}
{
/reverse_related_entries}
{
/exp:weblog:entries}

I use an embed for each language which means I can collect all links for a particular language in one place.

If you want to simplify and sophisticate the templating system, then I suggest you separate form and content by creating a template group called ’global’ where you keep embeds containing the content of the site, again with language conditionals, that is,

{if segment_1==”en”}
this content
{if
:else}
other content
{
/if}

In that way you can edit the templates in one place, with the exception of the templates used for layout in the other template groups.

What are the benefits of this solution? For one, searches work as you define one weblog for each language. Second, let’s say you have 10-20 custom fields that need to be rendered in several languages, the amount of custom fields would pile up in a single weblog form and become quite unmanageable. Third, you can use url_title in the URL. Four, it is native to EE and you don’t need to tweak, hack or have any PHP skills.

In addition to the solution outlined above, I use the Template language plugin which sees to that error messages are displayed in the proper language. I also find it handy to use the Clone extension as you only have to clone an entry, change weblog and translate whatever needs translating.

Categories: