Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

Multi-site / Multi-languages with Sitecore

, 1 Dec 2011
Rate this:
Please Sign up or sign in to vote.
Multi-site / Multi-languages with Sitecore

My current client has a number of domains for various regions and some regions will support multiple languages, including Right-to-Left languages such as Arabic. So let's highlight what needs to be done in Sitecore and our code to allow for this requirement.

Web.Config

Screen1

Above you can see that we have 3 sites defined. The .com site has en as the default language, the .co.uk has en-GB and the .ae has ar-EG (arabic Egyptian). The next section goes over language fallback, but for now notice that .co.uk and .ae have a fallback to English.

Language Fallback

Alex Shyba who works for Sitecore has contributed a nice Shared Source module called Partial Language Fallback that allows Sitecore to fallback to a different language for an item or field if there is not a value available within the current language context. Alex goes into more detail about this module on his blog located here: http://sitecoreblog.alexshyba.com/2011/08/partial-language-fallback-module-update.html.

Multiple Languages

The client's requirement is that the .ae site should default to Arabic but allow the user to choose English if they prefer. We already set the default language to Arabic in our web.config above, so we have that covered but now we need the ability to set a site's supported languages.

Screen2

Above I have updated the Website Root template, which is the root template of each site item in my solution. We have added a Site_Languages treelist field that has the System/Languages as the source. This allows for the content authors to select which languages they want supported for each site.

Screen3

Changing Languages

Now that the backend is setup, we can create a control that can be used in the site's footer to appear when 2 or more languages for the site is available and allow the user to select a different language.

LanguageContext.ascx

Screen4

Our frontend code above is simply building out a dropdown list that is bound to the languages and it is adding a "selected" tag to the language that matches the current context.

LanguageContext.ascx.cs

Screen5

The ManageLanguages function is in charge of binding the repeater to the available languages and it only shows the repeater if there are 2 or more languages available. So in our .com and .co.uk sites, this control will not be displayed but it will show up on the .ae site.

If the request is a PostBack, then it will set the language context for the user and then redirect to the original url to ensure the page and any controls loaded before this point are aware of the context change.

site.js

Screen6

Then the last piece is simply to wire up the select box to submit the form on value change.

Right-to-Left Support

Still in proof of concept mode on this one but what I have so far to support right to left languages is to check to see if the current language context is right to left and if it is then swap out the stylesheet with a different one. I will post an update if this approach changes after our UI developers take a look at it.

Screen7

Permalink | Leave a comment  »

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

James Coleman
Technical Lead Independent Consultant
United States United States
___________________________
J A M E S C O L E M A N
Director, Technical Services
Linked-In: http://www.linkedin.com/in/jameswcoleman
Blog: ledtalks.wordpress.com
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
GeneralMy vote of 5 PinmemberKanasz Robert1-Dec-11 2:41 
Good one.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 1 Dec 2011
Article Copyright 2011 by James Coleman
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid