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 culture-specific decorated property.
[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 and parts not translated into fallback language.
Either from the edit user interface or programmatically, you can define language fallback and replacement rules for content. These rules are 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 you do not publish that language.
Load content
The LanguageLoaderOption
controls how you handle languages during loading. The overload:
var content = Locate.ContentLoader().Get<IContent>(contentLink)
is equivalent to:
var content = Locate.ContentLoader().Get<IContent>(contentLink, new LoaderOptions() { LanguageLoaderOption.FallbackWithMaster() });
In this case, you did not specify a language, so it loads the content in the same language as it routes the current request to (ContentLanguage.PreferredCulture)
. It also uses a fallback so that 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 you save the common properties; the first language version in which you created the content.
Use the overload that takes a CultureInfo
to load content in a specific language, as follows:
var content = Locate.ContentLoader().Get<IContent>(contentLink, CultureInfo.GetCultureInfo("sv"));
This is equivalent to:
var content = Locate.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. Do this when no specific language version is required (such as when reading a language-neutral property like ParentLink
) because it is faster and fallback rules are not applied, as follows:
var master = Locate.ContentLoader().Get<IContent>(contentLink, CultureInfo.InvariantCulture);
Updated 7 months ago