This topic describes the API for accessing, selecting and modifying languages, and strict language routing in Episerver CMS.
When describing the language concept in Episerver CMS, the following language setting types are mentioned:
See Globalization for information about the language management concept in Episerver CMS.
You can determine the current value by reading CultureInfo.CurrentCulture and set by setting Thread.CurrentThread.CurrentCulture. The information is a CultureInfo object and you can retrieve the language code (en-GB, sv-SE, and so on) from CultureInfo.Name.
Note: CurrentCulture cannot be a neutral culture because its primary purpose is to provide sorting and formatting information. This means that the langauge code must be something like en-GB or sv-SE. Trying to use a neutral culture results in an exception when assigning the culture to CurrentCulture.
Compile a list of preferred languages in the following priority order:
Note: ** Valid means that there is a CultureInfo with the specified language code and that the language is not a neutral culture.
If you want to customize the selection logic, you can modify CurrentCulture in the InitializeCulture() method (virtual method on System.Web.UI.Page). The default implementation is done in EPIServer.PageBase.
The current value can be determined by reading CultureInfo.CurrentUICulture and set by setting Thread.CurrentThread.CurrentUICulture. The information is a CultureInfo object and you can retrieve the language code (en, sv, and so on) from CultureInfo.Name.
If you want to customize the selection logic, you can modify CurrentUICulture in the InitializeCulture() method (virtual method on System.Web.UI.Page). The default implementation is done in EPIServer.PageBase.
The preferred way to retrieve localized string resources in Episerver are through the LocalizationService API. For information about using this, see Localization service.
you can determine the current value by reading ContentLanguage.PreferredCulture. You can change the value by assigning this property. Content language can be a neutral culture. If sorting or formatting is required, you should read from ContentLanguage.SpecificCulture. The specific culture is evaluated on-demand and follows the .NET Framework rules for determining a specific culture from a neutral culture. See CultureInfo.CreateSpecificCulture.
The selection algorithm outlined above is implemented in ContentLanguage.DefaultContentLanguage and can be overridden by inheriting from ContentLanguage and assigning an instance of the new class to the static property Instance on ContentLanguage.
See Globalization scenarios for information about language-specific content settings in Episerver CMS.
Strict language routing causes the display of an error message if the URL and language-host mapping do not match. The following examples show how the language routing works. Say, for example, that on a website there is a page under root named News in English and Nyheter in Swedish. Given that no language mapping is defined for site hosts in configuration file, the URLs are handled as follows:
When a language to host mapping is defined, then a URL like http://localhost/en/News/ produces a 404, because when there is a host mapping that defines a language, the language should not be present in the URL.
You can modify the strict langauge routing behavior with a configuration setting strictLanguageRouting on the configuration element applicationSettings that can be set to false to get a more "tolerant" behavior.
Last updated: Oct 27, 2016