sitecoremultilingualsitecore8sitecore8.1

Language Fallback not working for Fields with Standard Values (Sitecore 8.1)


We had an issue where we enabled fallback language settings at the item level on a base template so that it would apply to all of our items. It worked for about 90% of our items but not for others even though the sitecore content editor indicated that it was working.

Placing this here for anyone else who has this issue. I didnt find a specific solution for this issue on Google and was lucky enough to figure it out. Hopefully this can help someone else out too.

Our setup is Sitecore 8.1 with Habitat Asp.net MVC


Solution

  • Here are some steps to make language fallback work for all items by applying item level settings to a base template.

    Step 1

    First step to enable language fall-back is to set up the fall-back tree. We can build a hierarchical structure (or simple linear) for languages to fall back to Example:

    Tree Fallback example

    In our case we would just do: EN-NZ --> EN

    This is done /Sitecore/System/Languages by setting the fall-back language on each of the language nodes:

    enter image description here

    Step 2

    Next we enable the language fall back feature for the site. At the deployed website locate the config file Sitecore.LanguageFallback.config And modify the config so that the following settings apply:

    <setting name="LanguageFieldFallback.AllowVaryFallbackSettingsPerLanguage" value="true" />
    …
    <sites>
          <site name="shell">
            <patch:attribute name="enableItemLanguageFallback">true</patch:attribute>
            <patch:attribute name="enableFieldLanguageFallback">true</patch:attribute>
          </site>
          <site name="website">
            <patch:attribute name="enableItemLanguageFallback">true</patch:attribute>
            <patch:attribute name="enableFieldLanguageFallback">true</patch:attribute>
            <patch:attribute name="enforceVersionPresence">true</patch:attribute>
          </site>
        </sites>
    

    Recycle the app pool

    Step 3

    Now the feature is enabled for the site we must enable the feature at the item level.

    1. Navigate to an item in the sitecore content editor and view the Advanced section
    2. If the Advanced section is not visible; select the View tab and check the Standard fields option
    3. Check the Enable Item Fallback option. (Displays item from fallback language if no language version exists )
    4. To restrict a page to a certain language, check the Enforce Version Presence option. 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.

    We can apply these settings on the Standard Template and the setting will apply to all Items that inherit it

    1. Navigate to the Standard Template
    2. Create a Standard Values if does not exist
    3. Set the Enable Item Fallback option

    This will get 90% of our items and fields working, however there is a caveat; this only works for fields that do not inherit their values from Standard Values.

    You can easily identify these fields by viewing the Item in the content editor

    enter image description here

    This is something to do with how the Enable Item Fallback option is also inherited from Standard values of Standard Template and Sitecore won’t apply the setting to the fields that also inherit from standard values.

    To handle fields/items in this scenario you do one of two things:

    1. Modify the field on the Item so that it does not inherit from standard values OR:
    2. Create a standard values on the Item template – It will inherit the Enable Item Fallback option from the Standard Values of the Standard Template
      1. Uncheck the option and Save
      2. Recheck the option and Save so that it no longer inherits the setting
      3. Now that the Enable Item Fallback option is not inherited it will apply. The fields on the item that inherit from standard values will now fallback and render

    Note: I believe this is a bug because the content editor still displays the fields as inheriting their content from the fall back language when you change language however the content doesn’t render on the website until you do one of the methods mentioned above

    Comments