Tuesday, April 14, 2015

Language Fallback: A word of caution

The concept of Language Fallback in Sitecore is great, actually having the ability to have Sitecore return content in a different language if none exists in the current context is tremendously helpful.  Even the concept behind this functionality is pretty straight forward. 

The module simply checks if there is a version in the current language.  If not it checks if there is a fallback for the current language and repeats the process on that language if there is until it either finds a version of the item or creates an empty item to return. 

Due to the simplicity of this module it has continued to work with every version of Sitecore since it was introduced, and will likely continue working for years to come.

Unfortunately, if you think about the recursion in this module there is a large problem that can happen.  Endless loops can occur when languages eventually fall back to the original language.

The current module in the marketplace written by Alex Shyba does not have checks to ensure that you do not have an endless loop.  Nikola Gotsev and I ran into this problem a while back where we had a language that would fall back to another language that fell back to the first language.  Not knowing this content error had happened led us into a bit of a nightmare of disabling modules and checking changes to find what brought our environment to its’ knees.

Nikola actually posted a fix for this last month.  This fix simply includes checking if we have already fallen back to a specific language (by enumerating fallback languages in a list).  This solves the problem no matter how complex the chain is.

No comments:

Post a Comment