Sitecore XM Cloud: Enabling language fallback with Keynotes on Configurations
Language fallback is a powerful feature provide by Sitecore, that allows showing the content in the set fallback language if the content is not found in current language.
Example, if you have setup your
site in 2 languages in which English will be the default and other as Arabic, with
Language fallback settings are enabled, if content for Arabic language is not
created and accessed then English language content will be use instead.
According to me, the best feature it offers is that it lowers
down the risk of showing 404 Page not found error if any page content is not
available in secondary language due to any reason.
In this blog, I would show you
how you can enable these settings in XM Cloud CMS along with creating the patch and show you how it works.
In case if you are seeking any documentation on How to add additional Language in your XM Cloud site, then you can follow this blog.
Types
You can setup Language fallback setting in 2 ways:
On Item Level
I recommend using this approach as this make things very cleaner and with less confusions as the fallback logic applies to whole of the content item. To set up the fallback, go the _Standard Values of the item. Currently I have setup on the Page Template which comes as stock.
This means, the page items created from this template will carry this setting enabled. Same way you can set on your Data Templates Items which basically will contain content.
On Field Level
Choose this approach, where you want to set the fallback logic on certain fields out of whole template.
This option is in Data Field Section.
[Important Note]
If you add a new language to the site, then that language appears on every item in the content tree and so as the fallback settings. The Language fallback settings must be applied only on those template/field items which will actually store the content only. Below i will enable the settings on Page Template Item and Data Source Template Item only.
Configuration
Before we proceed further, first thing is to set the
fallback on secondary Language.
Step 1: Setup Fallback Language as English to Arabic
Language.
Step 2: Enable Fallback settings on Item or Field Level
As mentioned in Types section above, you can enable the
settings as per your approach.
In my case, I have setup the fallback settings on Page
Template Item and Data Template Item.
Data Template:
Page Template:
Step 3: Enable Site Level fallback using Patch
This is the most important setting which I was missing due
to which language fallback was not working.
Basically we need to set the value true for enableItemLanguageFallback
and enableFieldLanguageFallback properties.
To see the current values, you can open up showconfig.aspx on your cloud cms.
Open the authoring solution, Goto your repository and open
the XMCloudAuthoring solution
Now, create a patch like below:
<?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>
Now, most importantly, Build the Solution
As you can see above, the patch file has been added to the proj file. Now commit the changes and deploy the app using XM Deploy App.
Before Patching the values were set as false:
After Deploy:
Now we are ready for testing.
Testing
[Important Note]
Language fallback will only
work if you do not create any version in secondary version. Otherwise, it will
try reading the empty values from item fields.
Before enabling the settings:
After enabling the settings:
Page Item State in CMS:
Since the version is not created in Arabic Language, the
content is used from English Language instead.
Conclusion
In this blog, I tried covering all the aspects which you
need to considering while enabling the language fallback in Sitecore XM Cloud.
Comments