Thursday, January 23, 2014

Languages in Sitecore

Languages in Sitecore
This is a brief overview of languages in Sitecore and Language fallback.  You can find a video on this here.

Quirks of Languages in Sitecore
Sitecore out of the box has some quirks when it comes to languages.  These are not flaws with Sitecore, but just things to keep in mind.

First the default language is non-regionalized English en whereas the other 4 available client languages are regionalized such as Danish which is regionalized to Denmark as da-DK.   This is likely due to the more global nature of English compared to the other available client languages.

Do keep in mind that though there are only 5 standard client languages, you can have as many content languages as you want.  The client language is just the language used in the Sitecore environment.

Inability to change content language
You cannot simply change the language of an item.  If you wish to change an item’s language you must create a new version of that item in the language you want it to be in and then copy the content over. 

As this is a tedious process make sure you know what language you want your content to be in before you enter any content.  

You don’t want to enter everything in United States English and find out later that the site is actually going to be featured in Europe and need to add everything again in British English

Lack of fallback support
For most users this setup is not a big deal as they will likely be in a single language or region.  

Though this can get tricky when you go into needing region specific languages as by default there is no fallback when content does not exist in a language.

For example, if you request an item in en-US or en-GB that exists, but does not have content in that regionalized language, it will simply return a null item, even if there is a version in the non-regionalized en. 

Language Fallback
Fortunately there is a shared source module called the Language Fallback Item Provider that does a pretty good job at resolving this issue. 
  • What is it?
    • The Language Fallback Item Provider shared source module can be found in the Sitecore Marketplace found here.
    • This module adds a field to the registered language item that allows us to select a language to fall back to if the item does not exist in the selected language.  
    • You must register every language that may be requested and assign it a fallback language.  Do note that you can only have one fallback language for each registered language. 
  • How does it Work?
    • Language Fallback works by first checking if the selected item exists in the current language.  
      • If it exists then it returns the item.  
      • If it does not exist it checks the registered language item.  If the language is registered and has a fallback language it will switch the context to that language and try again. 
    • This process is repeated until an item is found or until there is no Fallback Language, in which case it will return a stub item which is basically an empty item with standard values.


Partial Language Fallback
Partial Language Fallback is a Field Level fallback that offers far more control in how fallback works.

  • Field Level Fallback
    • At a field level you have the ability to enable and even enforce language fallback.  This allows you to have only the content you want fall back, such as banners and images.
    • Enforcing fallback causes the value from the content in the fallback language to be brought over much like a standard value.  It will keep in sync with the fallback content until it is modified and the link is broken.
  • Easy Regionalization of Content
    • Since enforced fallback works similar to standard values you can populate a base language such as English (en) with content, and then create regionalized versions (en-US, en-GB, ets...) that fallback to that base and the content will be brought over similar to a standard value.  This is quite helpful when there are only small differences between the regions.
  • Control
    • In your site definition you can enable fallback for a specific site, you can also require a items to have a version in the content language before any fields will fall back.



Possible Problems
There are a few problems that you might run into with language fallback, again none of these are really flaws with the system, just things to note.
  • Circular References
    • Though you can chain fallback, you need to watch out for circular links such as en-US falling back to en and then en falling back to en-US as this could potentially cause an infinite loop when trying to find the item.  Though the code likely has a catch for this it can cause performance problems, and can be unpredictable.
  • Unexpected or Incorrect Content
    •  If a page is requested and there is no content for that page, or some content on the page is not available in the current language.
      • If there is not fallback for the language or there is no content in the fallback language, the page may not display correctly.  
      • If you fallback multiple times, you may get content you were not expecting.
    • Unfortunately there is no default for language fallback, this means that if there is not a fallback language set for a language it will not default to any language.  It just simply will not fall back.



In Sitecore it is important to understand how languages work and the quirks associated with them.

Even though Language Fallback is available it should not always be relied on.  

From a content or code point of view.  The site should function with or without it enabled, you must always be aware of the content available and what languages may be requested.  

Having a language fallback plan setup prior to the content being deployed is key to preventing possible fallback problems and rework. 




No comments:

Post a Comment