PowerShell Script for Sitecore GUI language translation

I recently had this wild (day) dream of seeing the Sitecore GUI in tamil. While I leave you with the thought if I don't have anything else to dream about, I was finding blog posts specifically converting to tamil language. Like everything in Sitecore, I understood the platform provides you the necessary framework and it is up to you to use it to your benefit. This is where the client translations section in the Sitecore downloads page is useful. Only Danish, German, Japanese and Chinese xml files are available to download. Based on the documentation, this is how you go about changing the GUI language for the ones for which xml files are already available:

So, with that background, I started creating the tamil content xml file and then uploaded the same to a Sitecore 10.3 instance to see the standard GUI labels in tamil. So, what is special? Since there are about 11000 rows to translate, I created a PowerShell Script that can translate the Sitecore GUI content. In the end, I came up with a PS script that can take language code as input and create the xml file in the language of your choice.

Without much ado, here are the steps involved:

1. First things first, Based on Sitecore documentation, client translation files are actually here below as part of downloads page -

Client translation section:


After I downloaded and extracted the texts.ja-JP.xml file to use as reference for my translation, I followed the above documentation to add a language and do other shenanigans necessary for translation as per this blog post:

2. Switch to Core DB and add a new language through control panel as follows:




After selecting the language from the predefined language code field (tamil in this case) in above dialog, click Next button for this and subsequent dialogs and the language will be registered in the Core DB.

3. To check the same, go to Core DB content tree, traverse to /sitecore/system/Languages and you should have the newly added language:



The language code (ta-IN, in my case) displayed in the content tree is very important for the generation of translated content xml.

4. Next, I copy (the reference xml file) texts.ja-JP.xml to a local folder, in my case, c:\translate and I also add my TranslateGuiContent.ps1 PowerShell Script to the same folder.

5. Now, execute the PS script:

.\TranslateGuiContent.ps1 -file ".\texts.ja-JP.xml" -destfileLocation . -langCode 'ta-IN' -targetLanguage 'ta'

where,  targetLanguage  arg is first part (before hyphen) of langcode(from the Core DB languages list) and file is your reference xml file that should be downloaded from the Sitecore site.

destfileLocation points to current directory 

PS Script process flow:


Since this script processes about 11,000 rows will take a while to finish - ~20 minutes. 

Once the processing is done, copy over the created file (texts.ta-IN.xml file in my case) to <web root>/sitecore modules/localization folder.

6. Open control panel > Import languages dialog, select the above texts.ta-IN.xml file, the language of the file will be automatically detected (Tamil language in this case) and Database dialog points to core db (leave as-is) so, just click Import button and wait until processing/import is complete (~20 mins):


7.  After import is complete, go to control panel > Regional and Language options and you must find the newly added language. Select the same and press Apply button:



8. Once you press the Apply button, you should get the first symptom of the translated content:


Since I'm ok with the language change setting, I press the Ok button.

9. I then access the content editor and I can get glimpses of the translation effect on GUI:

 
Now, in future you can use this PS script and convert the Sitecore GUI to any language of choice listed in the predefined language code dropdown (~150 languages) present in Control Panel > Add a New Language dialog. Only thing is, you need to add the language in Core DB and find the language code as explained above in step 3.

One issue I noticed is, the labels are not visible in launchpad, control panel to name a few. I'm unsure if this is an indexing issue or something else that needs to be investigated since this misbehaviour is seen even in case of Japanese language file that is part of the Sitecore downloads page.

Otherwise, a random check of Hindi translation also looks fine:


Afrikaans language xml (generated file for reference):


Interesting fact(s):

a. One of the most important points to note is, the translated xml file must be in utf-8 encoding format. You can refer this stack exchange answer to see how to check encoding format of a file in windows. Without utf-8 encoding format, you will get an invalid file format message (as below) while importing the language in step 7. Note that the PS script takes care of saving the xml file in utf-8 format. 

The format of the language file "/sitecore modules/localization/texts.af-ZA.xml" is invalid.


b. In step 2, if you don't switch to Core DB before adding language, the language code wouldn't be visible in Core DB content tree (step 3)

c. As highlighted in point 9, after translation, the control panel links were blank and I couldn't get back to old settings, in other words, the control panel looked like this:


With a basic idea that the dialog is loaded from sitecore\shell\Applications\ControlPanel\Preferences\RegionalSettings\RegionalSettings.xml, instead of digging deeper into Sitecore.Client.dll, i decided to do a hack:

Since the tag text was blank, I edited the browser html to add text and could launch the dialog to reset to english as follows:


The other way to access the english launchpad is to pass sc_lang=en as query string param:
 <host name>/sitecore/client/Applications/Launchpad?sc_lang=en

Comments

Popular Posts