Tailwind Logo

XM Cloud - Language Fallback Settings

XM Cloud

Published: 2024-09-10

When operating a multilingual site, if it is possible to display information in another language if there are untranslated parts, it will be possible to display content in English first before translation. I would like to introduce this feature.

What is language fallback?

In a multilingual site, the operation of publishing information in all languages after it has been translated can create a bottleneck in the translation process. For this reason, it is often a procedure to first translate the main languages and then publish the pages after translation.

In this case, if there is a mechanism to temporarily display pages in a different language, it is possible to proceed with the translation of pages that should be translated and display them in a different language in the meantime. This mechanism is called language fallback. For example,

  • English content is always provided.
  • When deploying French, Spanish, etc., English if untranslated, release translated version after translation is complete

This is how it works. Now, let's enable language fallback in XM Cloud and display the data as en-US instead of en.

The procedure is available on the following page.

Language fallback settings

Add language

First of all, Sitecore has English content in en by default, so we need to add a language so that it can be used as en-US. When adding a language, a Fallback Language field is provided, so set en to this field.

xmclangfallback01.png

Enable Settings

Then, the following two items are disabled in the standard XM Cloud configuration

XML
<setting name="ExperienceEdge.EnableItemLanguageFallback" value="false"/>
<setting name="ExperienceEdge.EnableFieldLanguageFallback" value="false"/>

To change the above configuration, prepare a patch file to change the config in docker\build\cm\App_Config\Include\zzz\languagefallback.config. The contents of the file are as follows

XML
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
    <sitecore>
        <settings>
            <setting name="ExperienceEdge.EnableItemLanguageFallback">
                <patch:attribute name="value">true</patch:attribute>
            </setting>
            <setting name="ExperienceEdge.EnableFieldLanguageFallback">
                <patch:attribute name="value">true</patch:attribute>
            </setting>
        </settings>
    </sitecore>
</configuration>

To copy this configuration file to the Docker container, add the following lines to the file docker\build\cm\Dockerfile

Plain Text
# Copy Config files
COPY .\App_Config \inetpub\wwwroot\App_Config

Make sure config has changed after the change.

xmclangfallback02.png

Enable language fallback

First, check the following two items in the Language section of your site's settings to enable language fallback for your site.

  • Enable item language fallback .
  • Enable field language fallback.
xmclangfallback03.png

Next, we will enable it for the item template. In this case, we will enable the Standard Value item for the Page item.

xmclangfallback04.png

Finally, check the Enable Item Fallback - Display item from fallback language if no language version exists item in the Advanced section of the Page template.

xmclangfallback05.png

There is also how to set language fallback for items in data fields, but this part will be omitted this time.

Operation check

Now that we have added the language on the CMS side, we also need to make a change regarding the Next.js configuration: add en-US to the file src\sxastarter\next.config.js.

JavaScript
  i18n: {
    // These are all the locales you want to support in your application.
    // These should generally match (or at least be a subset of) those in Sitecore.
    locales: ['en', 'ja-JP', 'en-US'],
    // This is the locale that will be used when visiting a non-locale
    // prefixed path e.g. `/styleguide`.
    defaultLocale: jssConfig.defaultLanguage,
  },

You can now access https://www.sxastarter.localhost/en-US. You will see the following content in English.

xmclangfallback06.png

If you access the Home item in the content editor and browse the list of languages, you will see the Fallback version as shown below.

xmclangfallback07.png

If you start the Experience Editor in your local environment and switch the language to en-US, you will see a warning at the top of the screen.

xmclangfallback08.png

From this screen, you can switch to the target language or create a new version.

Reflecting on the XM Cloud environment

The above verification was configured in a local environment. In order to deploy, it is necessary to expand the config file. Therefore, copy the config file created above to src\platform\App_Config\Include\zzz\languagefallback.config and add definitions to src\platform\Platform.csproj as items to be copied Add the definition to src\platform\Platform.csproj as

XML
  <ItemGroup>
    <Content Include="App_Config\Include\zzz\languagefallback.config" />
    <Content Include="App_Data\items\core\localization\cmp.items.core.ja-JP.dat" />
    <Content Include="App_Data\items\core\localization\dam.items.core.ja-JP.dat" />

After making the above changes, rebuild the XM Cloud environment to reflect the code. If the Show config in the new CMS reflects the same settings as in the Docker environment, you can use the new CMS.

Summary

By skillfully using this language fallback for multilingual sites, it will be possible to efficiently run operations in multiple languages. For example, Japanese and English can always be created as the base language, and other languages can be translated if there are many PVs. Whether or not such operation is possible with a CMS is also a point of evaluation when it comes to a multilingual site.

Tags