Loading...
Area: Optimizely CMS
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Recommended reading 

Adding languages

This topic describes how to add a new language that does not appear in the list of available languages in the Manage Website Languages function in Admin mode. This is useful when you want to add less commonly-used language and local combinations on an Episerver CMS installation.

Adding a language to the list of available languages

Episerver CMS takes the list of the languages that you can enable for a site from the languages that are installed on the host operating system. This can be a problem because the available languages can vary between different machines. The risk exists if you have a language enabled in your Episerver CMS database that is not installed on your target machine, then an error occurs on start-up, which disables the entire site.

If you want to add a new language to Episerver CMS then you need to install it on your operating system through the CultureAndRegionInfoBuilder class in System.Globalization, which lets you create a new language from scratch or by copying it from an existing language, (although you will have to run the code in the context of an Administrator account for it to work).

The following code sample shows how to use CultureAndRegionInfoBuilder to create and register a new language based on an existing language, in this case creating Hong Kong English (en-HK) from UK English (en-GB). You need a reference to sysglobl.dll in your project for this to compile.

C#
public static void CreateCulture()
{
    //* Get the base culture and region information
    CultureInfo cultureInfo = new CultureInfo("en-GB");
    RegionInfo regionInfo = new RegionInfo(cultureInfo.Name);

    //* Create the a locale for en-HK
    CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = new CultureAndRegionInfoBuilder("en-HK", CultureAndRegionModifiers.None);

    //* Load the base culture and region information
    cultureAndRegionInfoBuilder.LoadDataFromCultureInfo(cultureInfo);
    cultureAndRegionInfoBuilder.LoadDataFromRegionInfo(regionInfo);

    //* Set the culture name
    cultureAndRegionInfoBuilder.CultureEnglishName = "English (Hong Kong)";
    cultureAndRegionInfoBuilder.CultureNativeName = "English (Hong Kong)";

    //* Register with your operating system
    cultureAndRegionInfoBuilder.Register();

}
  1. Run the code.
  2. Start Episerver CMS.
  3. Go to the Admin view.
  4. Select Config tab > Manage Website Languages.
  5. Click Add Language. Your new local combination is ready to use.
Do you find this information helpful? Please log in to provide feedback.

Last updated: Sep 21, 2015

Recommended reading