Exam Area: Content Area 1 – Product Knowledge (15%)
Reference: https://docs.developers.optimizely.com/content-management-system/docs/globalization
Optimizely CMS has built-in multi-language support. Each content item can have multiple language versions.
en, vi, fr){
"EPiServer": {
"CMS": {
"DefaultLanguage": "en"
}
}
}
services.Configure<RequestLocalizationOptions>(options =>
{
var supportedCultures = new[] { "en", "vi", "fr" };
options.SetDefaultCulture(supportedCultures[0])
.AddSupportedCultures(supportedCultures)
.AddSupportedUICultures(supportedCultures);
});
Properties can be:
[ContentType(DisplayName = "Article Page", GUID = "...")]
public class ArticlePage : PageData
{
// Different value per language
[CultureSpecific]
[Display(Name = "Heading")]
public virtual string Heading { get; set; }
// Shared – same value for all languages
// (no [CultureSpecific])
[Display(Name = "Sort Order")]
public virtual int SortOrder { get; set; }
}
If content does not yet have a translation for the requested language, CMS can use a fallback:
// Configure fallback
services.Configure<LanguageOptions>(options =>
{
options.FallbackBehavior = LanguageFallback.FallbackToMaster;
});
FallbackToMaster – Use the master languageNullIfNotExists – Return null if not foundFallbackByLanguageBranch – Fallback along a language chain// Get content in a specific language
var languageSelector = new LanguageSelector("vi");
var vietnameseContent = _contentRepository.Get<ArticlePage>(
contentLink, languageSelector);
// Get all language versions
var allVersions = _contentRepository.GetLanguageBranches<ArticlePage>(contentLink);
// Get in the current language
var currentContent = _contentRepository.Get<ArticlePage>(contentLink);
CMS uses XML files to localize the interface:
<!-- lang/en.xml -->
<languages>
<language name="English" id="en">
<contenttypes>
<articlepage>
<name>Article Page</name>
<description>A page for articles</description>
<properties>
<heading>
<caption>Heading</caption>
<help>Enter the page heading</help>
</heading>
</properties>
</articlepage>
</contenttypes>
</language>
</languages>
This add-on package provides:
NuGet: EPiServer.Languages
// Site definition with languages
var siteDefinition = new SiteDefinition
{
Name = "My Site",
SiteUrl = new Uri("https://example.com"),
StartPage = ContentReference.RootPage
};
// Configure languages for the site
siteDefinition.Languages.Add(new CultureInfo("en"));
siteDefinition.Languages.Add(new CultureInfo("vi"));
https://example.com/en/products/ → English
https://example.com/vi/san-pham/ → Vietnamese
https://example.com/fr/produits/ → French
[CultureSpecific])[CultureSpecific], what is the property value? (Shared/Language neutral)LanguageSelector)FallbackToMaster mean? (Use the master language when a translation does not exist)