LANGUAGE FALLBACK
For the development of a website with multi-language content, it is oftentimes necessary to resolve the issue of taking over the content from another language, if the content for the given language version does not exist. Sitecore enables you to take the content from another language version both on the level of an item as well as on the level of individual fields. This function is called Language Fallback. Sitecore implements Language Fallback since version 8.1.
Enabling Language Fallback
Due to performance reasons, Language Fallback is completely switched off by default. To enable Language Fallback, it is necessary to create a patch to change the attributes enableItemLanguageFallback and enableFieldLanguageFallback for site shell (Content Editor) and site website. A patch must be applied on Sitecore.LanguageFallback.config file.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
<sitecore>
<sites>
<site name="shell" set:enableItemLanguageFallback="true" set:enableFieldLanguageFallback="true" />
<site name="website" set:enableItemLanguageFallback="true" set:enableFieldLanguageFallback="true" />
</sites>
</sitecore>
</configuration>
To use versioned fallback for fields, it is necessary to also enable the LanguageFieldFallback.AllowVaryFallbackSettingsPerLanguage parameter in the settings.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
<sitecore>
<settings>
<setting name="LanguageFieldFallback.AllowVaryFallbackSettingsPerLanguage" value="false" />
</settings>
</sitecore>
</configuration>
Language Hierarchy
For the proper functioning of Language Fallback, it is necessary to define the hierarchy according to which language versions will be processed if Language Fallback is applied. In /sitecore/system/Languages, it is necessary to select a language on the language item in the Fallback Language field, from which the content will be taken over, if it does not exist in the given language. One language can have one Fallback Language. Multiple fallbacks may be achieved by defining another Fallback Language in the superior language, from which fallback has already taken place. On a global web, the English language will typically be the highest in the hierarchy. The English language for Great Britain referring to the global English language will be lower in the hierarchy. Then, a language for Ireland may also exist, where the fallback is set to the language for Great Britain. If no language version content for Ireland exists, then the content is taken over from the Great Britain language version. If this language version also does not exist, the content from the global English language is used.
Levels of Language Fallback
It is possible to use Language Fallback for the whole item or only for a selected field. Moreover, fields can only be fallen back in selected language versions.
Item Language Fallback
Language Fallback on the item level means that if the language version of the item does not exist, then the existing language version will not be uploaded from the superior language according to the defined hierarchy. Item Language fallback is turned on separately for every template in __Standard Values using the Enable Item Fallback field in the Advanced section. This setting is shared. Therefore, it is switched on for all language versions at once. Similarly Item Language Fallback can be turned on in Advanced section of a single item.
The language selector on a fall-backed item then shows on all languages with defined fallback language as one version exists. Once the language version, which does not exist, is open, a warning notification appears saying that the version for the given language does not exist and the version of a different language is displayed.
Field Level Fallback
Language Fallback on the level of individual fields ensures the taking over of the content field, which is not filled in, when the language version does not exist. In this case, the content from the superior language version is used. The Fallback field is switched on the field of the template using Enable field level fallback, for example, Enable versioned field level fallback. The first setting is shared for all language versions. Therefore, the fallback will always be used for fields with no value.
Versioned field level fallback
Using the second field, it is only possible to use the Language Fallback for the field for language versions, where this option is checked off in the __Standard values. Nevertheless, this option has a negative impact on the performance. Therefore, it is necessary to enable to function in the configuration. Then, it is possible to define the fallback for example, on only one field in __Standard Values in the language mutation for Ireland and leave the fallback switched off for the Great Britain version.
Tips
Enabling Language Fallback
Due to performance reasons, Language Fallback is completely switched off by default. To enable Language Fallback, it is necessary to create a patch to change the attributes enableItemLanguageFallback and enableFieldLanguageFallback for site shell (Content Editor) and site website. A patch must be applied on Sitecore.LanguageFallback.config file.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
<sitecore>
<sites>
<site name="shell" set:enableItemLanguageFallback="true" set:enableFieldLanguageFallback="true" />
<site name="website" set:enableItemLanguageFallback="true" set:enableFieldLanguageFallback="true" />
</sites>
</sitecore>
</configuration>
To use versioned fallback for fields, it is necessary to also enable the LanguageFieldFallback.AllowVaryFallbackSettingsPerLanguage parameter in the settings.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
<sitecore>
<settings>
<setting name="LanguageFieldFallback.AllowVaryFallbackSettingsPerLanguage" value="false" />
</settings>
</sitecore>
</configuration>
Language Hierarchy
For the proper functioning of Language Fallback, it is necessary to define the hierarchy according to which language versions will be processed if Language Fallback is applied. In /sitecore/system/Languages, it is necessary to select a language on the language item in the Fallback Language field, from which the content will be taken over, if it does not exist in the given language. One language can have one Fallback Language. Multiple fallbacks may be achieved by defining another Fallback Language in the superior language, from which fallback has already taken place. On a global web, the English language will typically be the highest in the hierarchy. The English language for Great Britain referring to the global English language will be lower in the hierarchy. Then, a language for Ireland may also exist, where the fallback is set to the language for Great Britain. If no language version content for Ireland exists, then the content is taken over from the Great Britain language version. If this language version also does not exist, the content from the global English language is used.
Levels of Language Fallback
It is possible to use Language Fallback for the whole item or only for a selected field. Moreover, fields can only be fallen back in selected language versions.
Item Language Fallback
Language Fallback on the item level means that if the language version of the item does not exist, then the existing language version will not be uploaded from the superior language according to the defined hierarchy. Item Language fallback is turned on separately for every template in __Standard Values using the Enable Item Fallback field in the Advanced section. This setting is shared. Therefore, it is switched on for all language versions at once. Similarly Item Language Fallback can be turned on in Advanced section of a single item.
The language selector on a fall-backed item then shows on all languages with defined fallback language as one version exists. Once the language version, which does not exist, is open, a warning notification appears saying that the version for the given language does not exist and the version of a different language is displayed.
Field Level Fallback
Language Fallback on the level of individual fields ensures the taking over of the content field, which is not filled in, when the language version does not exist. In this case, the content from the superior language version is used. The Fallback field is switched on the field of the template using Enable field level fallback, for example, Enable versioned field level fallback. The first setting is shared for all language versions. Therefore, the fallback will always be used for fields with no value.
Versioned field level fallback
Using the second field, it is only possible to use the Language Fallback for the field for language versions, where this option is checked off in the __Standard values. Nevertheless, this option has a negative impact on the performance. Therefore, it is necessary to enable to function in the configuration. Then, it is possible to define the fallback for example, on only one field in __Standard Values in the language mutation for Ireland and leave the fallback switched off for the Great Britain version.
Tips
- It is possible to use both levels at the same time on one template but it is not recommended.
- Fallback only works on fields that do not have any value defined. If we have inserted a value and then only deleted it, then the field has a value of an empty string and fallback will not be executed. It is necessary to reset the field to a value from __Standard Values using button Reset in group Fields of the Versions tab in Ribbon.
- The Item can be loaded with the applied fallback from the code without having to enable Language Fallback for the whole website using the switchers: LanguageFallbackItemSwitcher or possibly LanguageFallbackFieldSwitcher. This is useful when you only have one specified area, where you want to use fallback. However, due to performance, yo do not want to leave the Language Fallback turned on for the rest of the website.
- Dictionary items have Language Fallback turned on by default