This article describes how to localize culture names rendered by localization web parts so they are rendered in the currently selected culture version.
When using a localization web part, for example the Language selection web part, culture names are rendered in a static way, according to the value of the “Short name” property of the given culture. This property can be found in the Site Manager -> Development -> Cultures section, edit a culture and go to the General tab.
By default, all these names are in English. So, no matter which culture version is in use, the live site will still display e.g.:
Czech, English, German
But you may want to see culture names in the language of the currently selected culture. For example, in the German culture the web part would render:
Tschechisch, Englisch, Deutsch
Let’s see how it is done.
As usual, Kentico CMS provides a quick and simple way of doing this.
First, we need to use an in-place localization expression in the “Short name” property of particular cultures according to the following example. If you are not familiar with this topic, please see the links below.
Then, we need to change the code-behind of the particular web part a little bit. In my example, I chose the “Language selection” web part, so I need to change the code in the <project folder>\CMSWebParts\Localization\languageselection.ascx.cs. Within the code, we need to find the part responsible for rendering culture names and change the following line:
string cultureShortName = Convert.ToString(dr["CultureShortName"]);
string cultureShortName = ResHelper.LocalizeString(Convert.ToString(dr["CultureShortName"]));
Using the ResHelper.LocalizeString method will ensure proper value replacement and the desired result.
Please note – if you can see any un-resolved in-place localization macros anywhere on your page, you have to modify the code-behind of the web part which renders it.
Kentico CMS 6.x
Created on 8/9/2012 6:30:31 AM
in Web parts & Controls