an easy solution to multilingual sites
Posted: 12 March 2007 03:15 AM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  226
Joined  04-23-2004

One of my greatest problems working with EE has been making a bilingual site that works. EE being a very flexible tool allows for so many ways to try out the best solution. The simplest and easiest way I’ve come up with is the following.

I try to be as modular as possible, which means that I create separate weblogs, template groups and category groups for each language. Different weblogs means that I can direct searches to different pages in different template groups, and searches generally won’t work with only one weblog. What title to display? Which extract? It all turns into a mess.

It also means that I can use the same entry form for all languages without having to create different custom fields and different templates for each language. I only have to assign different variables and parameters to the templates so that the ‘wrong’ language won’t be displayed.

I then link the english version via the related_entries tag to the swedish, where I use the reversed_related_entries tag in the template to ensure that nothing goes wrong (and it’s simpler than to link back and forth in the forms).

The template groups I call “en” (english) and “se” (swedish). This allows me to script what should be displayed on each page by adding a conditional {if segment_1==“se”} this {if:else} that. Of course one could keep a single template group and just add the segment “en” etc to each URL.

I also assign categories in both languages to each entry. This has been the main problem, and still is to some extent. How do I tell EE what category to add in the URLs between the languages?  While it works to add {segment_2} or to use the category:weblog_heading tag in the URL, the page linked to displays as it should, except if I want to show the category heading, for instance, in the title of the page. There I get the ‘wrong’ or both both languages.

If I use the categories tag and the show not parameter I would have to do a lot of hard coding each time a parent category was added. No point in adding show=”{segment_2}  LOL This could be improved if the category_group parameter were allowed in the categories tag, then it would be possible hardcode the URL once.

Finally, I only have to add this code for each language to make the linking work just fine.

{if segment_1==“se”}
{exp:weblog:entries weblog=“my weblog_se” limit=“1”}
{if category_request}<a href=”{path=en}{segment_2}”>english</a>
{if:elseif url_title==”{segment_2}”}{reversed_related_entries}<a href=”{path=en}{url_title}”>english</a>{/reversed_related_entries}
{if:else}<a href=”{path=en/}”>english</a>{/if}{/exp:weblog:entries}

{if:else}
{exp:weblog:entries weblog=“my weblog_en” limit=“1”}
{if category_request}<a href=”{path=se}{segment_2}”>svenska</a>
{if:elseif url_title==”{segment_2}”}{related_entries id=“my_custom_field”}<a href=”{path=se}{url_title}”>svenska</a>{/related_entries}
{if:else}<a href=”{path=se/}”>svenska</a>{/if}{/exp:weblog:entries}
{/if}

 Signature 

Yvonne

———————————
freewheelin.nu | intermezzo | net.textualities

Profile
 
 
Posted: 12 March 2007 07:22 AM   [ Ignore ]   [ # 1 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  224
Joined  04-28-2006

One solution:
http://expressionengine.com/wiki/Multi_language_site_alternative/

have fun

Profile
 
 
Posted: 13 March 2007 04:04 PM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  122
Joined  01-05-2007

goeminnek, the wiki contains a radically different setup with all languages mixed in the same weblog. This solution not only appears to give you exactly the search-related issues that Yvonne mention in her post, it also requires posting to be symmetric in all languages - the same information posted in all languages, at exactly the same time. To use this technique, you basically must have parallel publishing processes so that all language versions become ready at the same time. This is a very peculiar requirement that in my experience is very difficult to fulfill. Apart from the fact that you may not want to publish exactly the same content in all languages…

Yvonne, I’m tired and it’s a bit difficult to understand your post. Perhaps you could simplify your solution a bit? Let’s assume that you just create one weblog for each language. Then you use global variables from the path.php file to hold the weblog name, the page, section and field headings, and any other text you need to use in the template.

"my_weblog" => "freewheelin_en",
"my_search_text" => 'Search',
"my_recent_text" => 'Previously',
"my_categories_text" => 'Topics',
"my_archives_text" => 'Archives',
"my_syndicate_text" => 'Syndicate',

I use this method and it allows me to use the same templates etc regardless of language, and without the complex scripting that I am too tired right now to try to understand in your post.

Would this work for you too?

By the way, the wiki solution gladly refers to language codes as “country codes”, and then uses “fr” as a “country code” which must be a problem for all the Canadians and Swiss that also have French as their native language.

In your case, you have used “se” for Swedish. However, in the ISO standard, “se” is a country code and stands for Sweden. As a language, it’s actually called “svenska”, with the language code “sv”. I’m sure your current abbreviation works fine on your own site, but if you’re thinking of doing EE work for money I believe you should use ISO language codes for languages and ISO country codes for countries. And of course this goes for the wiki solution as well.

Profile
 
 
Posted: 14 March 2007 05:00 AM   [ Ignore ]   [ # 3 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  779
Joined  12-01-2002
yvonne m. - 12 March 2007 03:15 AM

I also assign categories in both languages to each entry. This has been the main problem, and still is to some extent. How do I tell EE what category to add in the URLs between the languages?  While it works to add {segment_2} or to use the category:weblog_heading tag in the URL, the page linked to displays as it should, except if I want to show the category heading, for instance, in the title of the page. There I get the ‘wrong’ or both both languages.

If I use the categories tag and the show not parameter I would have to do a lot of hard coding each time a parent category was added. No point in adding show=”{segment_2}  LOL This could be improved if the category_group parameter were allowed in the categories tag, then it would be possible hardcode the URL once.

I’m not certain why your choosing categories in both languages. But I could be missing something. I run a similar set-up for a couple clients that need multi-language sites, when each language needs to be separately maintain (because not all articles are paralleled, and various languages get translated at different times.  My system mostly matches yours:

(1) Different Weblogs for Each Language (English, Spanish, Chinese, Korean, Russian, etc.)
(2) Each Weblog uses same field group
(3) Decision on whether weblog uses same category group or not (one client uses english categories across all languages, so a single category group; but another client translates categories, so a different category group per language). I prefer the first, since individuals who don’t speak the language can post foreign language documents. Though the second works well with a language cheat sheet.
(4) We use a publication ID to relate the same document across languages, and a custom query to pull a listing of languages the article is available in. Since weblog name (blog name) is the same as the language, we just check for pub_id and return blog_name. So languages get listed like (English, Spanish, Chinese, Japanese). Obviously with linking on the language name.
(5) Make sure weblog name (blog_name) matches template group name. This makes life so much easier for a slew of reason, but the number one being, urls are always correct, since we just specify the {blog_name} in the url path.

For example most of our language related urls look like {domain}/{blog_name}/article/{url_title}/

{domain} is a path.php variable, since we are running multiple sites in multiple languages

{blog_name} is equivalent to language and template group based on set-up, so english, japanese, spanish, chinese (we don’t abbreviate

{article} is the template inside the template group. Since article is in every template group, we actually use an embedded template, so that we can make modifications to all article templates from a single location

{url_title} obviously just the post title url specification

That’s it. It’s pretty much five steps. We do place some variables in path.php; but this isn’t specific to the language structure, but do to running multiple sites in multiple languages from a single install.

The one client runs 5-6 primary language, than has even more additional/‘random’ languages for some postings—for example someone may pay for an article to be translated into Japanese, even though Japanese isn’t one of the primary translation for the site. There are some adaptations for handling these random other languages. Typically, the weblog is called ‘other’, and a language field is added, so that people can selected from a pull down menu of other languages.

So far we’ve had no problems with the system. URLs always work the way we expect them, searches, etc. So I’d say your on the correct path, it seems that categories maybe your sticky point.

Profile
 
 
Posted: 14 March 2007 06:10 AM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  226
Joined  04-23-2004

Ok, Magnus, let me clarify and let’s assume that we have just one weblog for each language.


Weblogs

As far as concerns weblogs it’s very easy. The only thing you have to see to is that you assign the same field group to the weblogs so that the two weblogs mirror one another. Then you only have to work with segments, which is a powerful tool in EE.


Template groups

If you create two template groups, let’s say “se” and “en,” the weblog entries tag determines what to display. Sorry, I really can’t see why I should create global variables in the path.php file for this.

The tricky part is the linking between the languages, but let’s assume that we only have an index page here whose URL is www.mywebsite.com/index.php/en/. Then the link to the other language would simply mirror the URL.

<a href=“www.myweblog.com/index.php/se/”>

Personally I only use different template groups for layout, with embeds, and to give me a mental picture of my site structure. The content is in a third template group with all the modules that make up the pages, and in the modules I mix the languages. Thus, here I have to add a conditional.


{if segment_1==“en”}

<a href=”{path=se}”>svenska</a>

{if:else}

<a href=”{path=en}”>english</a>

{/if}


Of course, you can extend the links in more or less complex ways as long as it mirrors the requested URL. In fact the whole idea depends on mirroring.

Let me give you a few examples.

Linking single entries

You have to link the entries using the related_entries and the reversed_related-entries tags. First, create a custom field of the relationship kind and link the entries. Then, craft the URL to your single entries. Let’s assume the URL is www.myweblog.com/index.php/en/url_title. The mirrored link would be:

{related_entries id=“my_custom_field”}<a href=”{path=se}{url_title}”>svenska</a>{/related_entries}

and the corresponding link in Swedish

{reverse_related_entries}<a href=”{path=se}{url_title}”>english</a>{/reverse_related_entries}

But I only want to display this link if there has been a single entry request, thus, I have to add a conditional.

{if segment_2==”{url_title}”}

{related_entries id=“my_custom_field”}<a href=”{path=se}{url_title}”>svenska</a>{/related_entries}

{/if}

Furthermore, I need to work it all together with the different languages.


{if segment_1==“en”}

{exp:weblog:entries weblog=“weblog_en}
  {if segment_2==”{url_title}”}

  {related_entries id=“my_custom_field”}<a href=”{path=se}{url_title}”>svenska</a>{/related_entries}

  {if:else}

  <a href=”{path=se}”>svenska</a>{/if}
  {/exp:weblog_entries}

{if:else}

{exp:weblog:entries weblog=“weblog_se} 

{if segment_2==”{url_title}”}
  {reverse_related_entries}<a href=”{path=se}{url_title}”>english</a>{/reverse_related_entries}

 
  {if:else}
  <a href=”{path=en}”>english</a>{/if}

{/exp:weblog_entries}

{/if}


As you can see, the only coding I have to do is the coding of the URLs. While writing this I received the post by allgood 2, who seems to have a similar system (btw, the reverse related entries tag would show all the linked languages if it were a mulitlingual site).


Categories

As allgood2 says categories are my sticky point and he/she asks why I need categories in both languages. The answer is simply that I want to be able to switch between category pages AND display the category heading in each language without having to hardcode the URL.

For categories and every other request I have to go through the same procedure of working with URLs, segments and language. But, that is all. It takes some structuring and streamlining but it’s all done in one location.


Btw, Magnus, thanks for pointing out the difference between “se” and “sv.” Has always puzzled me.

 Signature 

Yvonne

———————————
freewheelin.nu | intermezzo | net.textualities

Profile
 
 
Posted: 07 July 2007 11:46 AM   [ Ignore ]   [ # 5 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  226
Joined  04-23-2004

After the upgrade to 1.6, there is no problem switching between languages. In fact, the new categories custom field and the {page_url} takes care of much. It all runs very smoothly, without hardcoding or hacks in path.php.

But, the problem is still auto-generated emails and stuff. I have the switch_language plug-in, or whatever it is called, I can’t find it! It takes care of message templates and the first e-mail in for instance the registration process. I thought of overriding this in the path.php file (in the case where I’ve made a site that is different from my main site), but the variables or configurations seems to have disappeared! I don’t mind bying MSM and probably will since it makes site managment much easier structurally, but I don’t seem to ahve choice as the variables described at http://expressionengine.com/wiki/Per_Site_Config/ don’t exist anymore! (I know, they must be somewhere… but I don’t find them).

Maybe this is really a pre-sales question, but I want to continue the thread I’ve used before, because a lot has been made much easier with 1.6. The question at moment is, can I use site-specific global variables and where do i find them, or do I need to install MSM?

 Signature 

Yvonne

———————————
freewheelin.nu | intermezzo | net.textualities

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 66456 Total Logged-in Users: 60
Total Topics: 84831 Total Anonymous Users: 25
Total Replies: 455247 Total Guests: 195
Total Posts: 540078    
Members ( View Memberlist )