Multilingual content
Describes how to create a content type that implements the ILocalizable interface in several language versions.
You can create a content type that implements the ILocalizable
 interface in several language versions. For example, pages and blocks have multilingual support, while media and folders do not have multilingual support. For a content type that implements ILocalizable
, you can define individual properties as culture-specific and have different values for each language. Properties that are not culture-specific are common through the different language versions. The following example shows a property that is decorated as culture-specific.
[CultureSpecific]
public virtual string Heading {
get;
set;
}
Fallback and replacement settings
Use fallback settings when you have translated parts of a site. The site displays the translated parts but displays parts that are not translated into the fallback language.
From the edit user interface or programmatically, you can define a language fallback and replacement rules for content inherited by content below the content in the structure where you defined the setting. For example, if you define and enable the fallback language B to replace language A for some part of the structure, a request for content in language A returns the content in language B.
You can use replacement while you add a language to a site but keep it inaccessible to site visitors until you have completed the translation of the whole structure by turning off the fallback language. Apply fallback settings when content does not exist in a language or if the content is not published in that language.
Load content
The LanguageLoaderOption
controls how languages are handled during loading. The overload on IContentLoader
:
var content = _contentLoader.Get<IContent>(contentLink)
is equivalent to:
var content = _contentLoader.Get<IContent>(contentLink, new LoaderOptions() {
LanguageLoaderOption.FallbackWithMaster()
});
In this case, language is not specified, so the content is loaded in the same language as the current request is routed to (ContentLanguage.PreferredCulture
). It also uses a fallback, so if the content does not exist or is not published in the language, it will fall back according to specified fallback rules with a final fallback to the master language. The master language is the language version where the common properties are saved; the first language version in which the content was created.
Use the overload that takes a CultureInfo
to load content in a specific language, as follows:
var content = _contentLoader.Get<IContent>(contentLink, CultureInfo.GetCultureInfo("sv"));
This is equivalent to:
var content = _contentLoader.Get<IContent>(contentLink, new LoaderOptions() {
LanguageLoaderOption.Specific(CultureInfo.GetCultureInfo("sv"))
});
A fallback option is not specified in this case, so no fallback rules are applied.
You can pass in CultureInfo.InvariantCulture
as CultureInfo
, which returns the master language version. This is useful when no specific language version is required (such as when reading a language-neutral property like ParentLink
) and it also is faster because fallback rules are not applied, as follows:
var master = _contentLoader.Get<IContent>(contentLink, CultureInfo.InvariantCulture);
Updated 9 months ago