Language Fallback in Sitecore 8.1

October 20, 2015

Language fallback is one of the new native features just launched in Sitecore 8.1. The implementation follows Alex Shyba’s fallback module, but it has been mostly rewritten for optimization purposes.

Language fallback, for those who are not familiar with the concept, is the ability to derive a value from a default language in the absence of the one requested by the user.

Initial Settings

The first step is to set the “Fallback Language” field in the language definitions found under /system/languages.

Language-Fallback-Sitecore-01.png

If no value is found in Portuguese, it goes to the English version and loads from there.

Chained Fallback

Sitecore’s language fallback supports chained fallback. You can chain the definitions in such a way that if a value is not found in the fallback language, it falls back to a third option, and to a fourth, and so on.

Here pt-BR and es-ES fallback to en, whereas es-AR, es-CL and es-MX fallback to es-ES:

Language-Fallback-Sitecore-02.png

Enable Fallback for the site

After setting up the language definition with the desired chain of fallbacks, you then need to enable fallback for the required sites.

You will find a configuration file called Sitecore.LanguageFallback.config where you will find the attributes enableItemLanguageFallback and enableFieldLanguageFallback for both the shell site and website site.

Download a custom configuration file that enables fallback for the default Sitecore website.

*It's preferable to create a new file with your custom settings to avoid breaking the Sitecore upgrade path. It is a future-proof change.

**Name your custom file in such a way that it’s located (alphabetically) after Sitecore’s default file. Sitecore always uses the latest found setting of an attribute when it's defined more than once.

Enabling fallback to the shell site is required – if fallback is in use – to allow your editor to visualize fallback items in the Content Editor mode.

Item-Level Fallback

Whether or not a whole item is able to fallback is defined in the item itself under the Advanced section.

Language-Fallback-Sitecore-03.png

*To view the Advanced section go to VIEW > VIEW > Standard fields in the ribbon and make sure this option is checked.

“Enable Item Fallback” field

The help text already describes it well. I just want to highlight that Sitecore will fallback only if no version of that item is available for publishing.

  • If there is no version whatsoever for the Item in that language, it will fallback
  • If there is any publishing restriction configured for the version in a given language, it will also fallback

*At the time of this post, preview mode is showing the fallback item, like it does when displaying the published item.

**To see publishing restrictions go to the Publish > Restrictions > View in the ribbon.

  • If there is an available version for the item in the selected language, it won’t fallback

“Enforce Version Presence” setting

In cases where a version is not found for a specific language, Sitecore's default behavior is to return an empty item. This happens when rendering an item or when trying to access it via Sitecore API.

In cases where there’s no version available for the requested language, this option allows you to tell Sitecore NOT to return an item. This will end up redirecting the user to a 404 (not found) page, or returning NULL when trying to get the item via API.

To enable this option, you first need to explicitly set enforceVersionPresence via config files for each site. Then you can start to use the Enforce Version Presence field on the items or standard values at the template level.

Language-Fallback-Sitecore-04.JPG

*Do not set this attribute for the shell site, otherwise you won’t be able to create new versions for an item.

Template-Level Fallback

To enable fallback for all items of a given template use the template's __Standard Values for it.

Dictionaries (/sitecore/system/Dictionary) are the only items that have fallback enabled by default on its standard values.

Field-Level Fallback

To enable field level fallback, select the Field item and in the Data section you get two option as shown in the image:

Language-Fallback-Sitecore-05.png

Both options allow you to define fallback only on specific fields of an item.

Enable Shared Language Fallback

In the image below, the field title has the “Enable Shared Language Fallback” field checked. You see that because we don't have a value specified in Portuguese, it “borrows” the value from the English version.

The behavior is quite straightforward. No value means it falls back as configured in the language “language fallback” field.

Language-Fallback-Sitecore-07.png

As a side note: the concept of shared fields still apply, as always. The concept of shared differs from the concept of language fallback. Fallback is useful when you may not have a field translated and you want to get the information from a base language, whereas shared is a property that says all values between all available languages must be the same.

“Enable Shared Language Fallback” looks to be the most useful setting. In some specific scenarios you may need to use “Enable Versioned Language Fallback”.

Enable Versioned Language Fallback

"Enable Versioned Language Fallback" will allow you to fallback only on a specific language and in a specific field.

Sitecore advises that the usage of versioned fallback has impact on performance. Because it affects performance, you need to enable versioned field fallback in the config file before using it.

Language-Fallback-Sitecore-08.JPG

Versioned Language Fallback Sample:

Let’s say, from the previous samples, that I want to fallback the title only when coming from its base language, in our case Spanish (es).

Title Field

en-US

Never Fallback

pt-BR

Never Fallback

es-ES

Never Fallback

es-AR

Fallback to es-ES

es-CL

Fallback to es-ES

es-MX

Fallback to es-ES

For that, you can set “Enable Versioned Language Fallback” only on the field’s item version of each of the languages you want to fallback.

Language-Fallback-Sitecore-09.png

You can see the end result in the table below:

en-US Never fallback Language-Fallback-Sitecore-09-A.png
pt-BR Never fallback Language-Fallback-Sitecore-09-B.png
es-ES Never fallback Language-Fallback-Sitecore-09-C.png
es-AR

Fallback to es-ES

Language-Fallback-Sitecore-09-D (1).png
es-CL

Fallback to es-ES

Language-Fallback-Sitecore-09-D (2).png
es-MX

Fallback to es-ES

Language-Fallback-Sitecore-09-D.png

 

Contact us

We would love to hear from you! Please fill out the form and the nearest person from office will contact you.

Let's reinvent the future