Sitecore Custom Language Registration and Fallback

On one of my recent Sitecore projects, we implemented custom languages for each country. The site supports multi-language for 100+ countries, with each country supporting between 1 and 4 languages.

The requirement was that each country supported it's own country code with each language code, for example, Germany, the site supports English, German and French for Germany which looks like this:
  • en-DE (English-Germany)
  • de-DE (German-Germany)
  • fr-DE (French-Germany)
The site also uses language embedding in the URL and a lot of the new Languages uses Sitecore Language Fallback as Content Authors don't maintain content in each and every language variant.

Problem: most of the site's Country and Language combinations are not supported out of the box by Windows Cultures and the default Sitecore Language lists which mean that we have to follow this process:
  1. Register a new Culture in Windows for each applicable Country and Language combination
  2. Add the new Language to Sitecore in sitecore\system\languages and configure the Fallback language if applicable
So I found a tool in Sitecore MarketPlace to register the new Cultures in Windows:




The tool works well, but the problem is you have to complete the form for each new Language-Country combination, so in my scenario, that means doing this on each CM and CD server for all the language options supported by the site.
For example, if we have to add 200+ custom cultures to Windows on 3 different servers per environment (plus any other new environment, say a Dev VM), it's both a tedious, repetitive and time-consuming task that screams for some type of automation.

To solve this problem I built a simple Console Application that reads a pre-configured CSV file with all the Language-Country combinations and Registers the new Culture for each row within Windows using the .Net System.Globalization.CultureAndRegionInfoBuilder classes in the sysglobl system assembly.

The application also produces a Sitecore Powershell file to add the new Languages to Sitecore in sitecore\system\languages - that further saves time compared to manually adding them in Content Editor.

Configuration Data

The application uses a CSV file as input to do the custom culture registration and also additional data in the CSV file applicable to the Sitecore Powershell script that the app generates to add the languages in Sitecore.

Configure the custom cultures in the CSV file first according to your Sitecore website multi-language requirements! This is usually a once-off exercise for a site's domain languages and then the CSV file can be re-used on multiple servers (CM or CD servers)



NewCountryName: Name of the new country - e.g. Ukraine

NewCountryCode: ISO Country code e.g. UA for Ukraine

NewEnglishCultureName: Langauge (CountryName) e.g. Russian (Ukraine)

BaseFromCultureCode: ISO Langauge-CountryCode e.g. ru-RU. Used to base the new culture off, in this example ru-RU = Russian-Russia

NewLanguageCultureCode: ISO Language-Country code for the new culture e.g. ru-UA

AddToSitecorePowerShellScript: Flag Y or N to indicate whether to add this language registration into a Sitecore Powershell script to add the new Language into sitecore\system\languages. This is done manually by executing the generated Powershell script from Sitecore Desktop

FallbackLanguageCultureCode: If this Language uses Sitecore Language Fallback, this option specifies the ISO language-county code for Langauge Fallback (e.g. ru-RU). Applicable for the Sitecore Powershell script

Active: Active Flag Y or N. If set to Y language registration will be done. If flag set to N, the language registration will be ignored, but based on the AddToSitecorePowerShellScript flag the info will still be added to the Sitecore Powershell script to add the language to sitecore\system\languages

Running the Application

The source code and current release for the application can be found on Github and can easily be extended or customized if desired. 

For most users there's no need to modify the source code so a downloadable release can be found here:















With the assumption that you edited the CSV file based on your site's language requirements, copy the files to a target server (e.g. CM or CD server) and Run it as Administrator. The application would then display like this:



It outputs some informational messages to the Console, select Y to continue...




The application will then register all the new Cultures in Windows and produce the Sitecore Powershell script to add the new Languages in Sitecore in the same directory.

Reboot the server for the changes to take effect! 

Only run the Sitecore Powershell script via Sitecore Desktop after the reboot, otherwise Sitecore won't pick up the new cultures.

Sitecore Powershell Script

As mentioned earlier in this article, the application also generates a Sitecore Powershell script to add the new Languages to Sitecore in sitecore\system\languages. The initial Powershell script to add a language is defined as a type of template where the code maps some of the CSV field data to the placeholders defined in the template (SitecoreAddLanguagesScriptTemplate.ps1):



It's a simple mapping in the code for now, can make this more configurable in a future release if desired.



Hope this application can save other people time too.

Cheers/F


Comments

Popular posts from this blog

Sitecore Salesforce Integration using Azure Microservices

Sitecore 8.2 Processing Server - Performance Tuning