Enable multiple languages
In Sitecore, there are a number of tools and architectural features for dealing with language and locale content. Sitecore is fairly unique, in that language versions are stored at the same location in the repository, making it easy from a usability (side-by-side viewing, etc.) and workflow perspective.
Adding a new language
You can manually create a language variation for an item in a language that is registered to be easily used, however best practices dictate that if you are using a language, chances are it is for more than a single instance and therefore you should indicate it use to make it easier for authors to use that language, as well as ensure the correct locale/language pairs are being used. To register a language, follow these steps:
1. Click Sitecore, and then click Control Panel.
2. Click Globalization in the Control Panel.
3. Add a New Language in the Globalization Control Panel.
The Add Language wizard appears. If you have not already disabled wizard welcome pages, a welcome page appears; click Next. The Language Codes page appears as shown below.
4. Select the appropriate language and region.
In the drop-down list at the top, select the appropriate language and region, and then click Next.Note that Sitecore comes with a list of common locale/language pairings. If you do not see the one you need, see "Creating Custom Locale/Language pairings". The Code page and Encoding page appears - for existing pairings you can accept the defaults.
5. Click Next. The Checker Dictionary page appears.
6. Enter the name of a spellchecker dictionary file for the language
For the Spellchecker file path, enter the name of a spellchecker dictionary file for the language from the /sitecore/shell/Controls/Rich Text Editor/Dictionaries subdirectory of the document root. If no file corresponding to the new language exists, leave this field blank. Then click Next. The completion page appears.
7. Click Finish. The Add Language Wizard closes.
You can now apply security or update other properties of the new language definition item under the /sitecore/system/Languages item in the Content Editor. You can use the "Language Read" and "Language Write" permission properties to restrict reading and editing content in a specific language for certain roles/users.
Creating custom Locale/Language pairings
Often you run into situations where you wish to have a different regional locale, even if the language already exists. For example, Singapore uses UK English for all spelling - however if you are serving this market, you likely don't want to use the exact same copy for both, as there is likely local pricing and copy for that region. In this case, the easist method is to simply select an existing language/region pairing that closely matches your requirements (i.e. Singapore Chinese) and change the language code to "en".
The new language is now visible on the Content editing tab (as well as other places in the User Interface). As you can see, it reflects both the language and locale (localized for each language as appropriate)
Incidentally, if you do still want to do a one-off language version for an item without registering the language first, this dialog is where you can select "More Languages" and add this manually.
API commands for not showing/linking to content if it does not exist in a language.
In some sites supporting multiple languages, CMS users do not translate every item before publishing. When working with multiple languages, it is important that your code ensure that a version of an item actually exists in that language before you link to it.
XSL: Use the system field '__created' as a predicate. For example:
- <xsl:for-each select="$sc_currentitem/item[sc:fld('__created',.)]">
C#: You can use Sitecore.Data.Items.Item.Versions.Count to determine if a version exists in the current language context. For example:
- foreach (Sitecore.Data.Items.Item child in contextItem.Children)
- if (child.Versions.Count > 0 )
- // Do something
Section 5.2 in the Presentation API Cookbook on SDN contains much more example code for dealing with languages.
Complex language configuration
Sometimes you site requirements may extend well beyond having simple language versions of the same item, to where you have multiple sites sharing content. There is another article on Launch Sitecore for dealing with Large Multi-National Sites. Another common example is that of "Language Fallback", which the article covers as well.