📚 Product Knowledge
Multilingual Content
📖 Docs

Multilingual Content - Optimizely CMS 12

Exam Area: Area 1 – Product Knowledge (15%)
Reference: https://docs.developers.optimizely.com/content-management-system/docs/multilingual-content


1. Language Branches

Each page can exist in multiple languages as language branches:

Each language branch is a translation of the same content item.


2. CultureSpecific Attribute

[ContentType(GUID = "...")]
public class ArticlePage : PageData
{
    // Translatable - each language has its own value
    [CultureSpecific]
    public virtual string Heading { get; set; }

    [CultureSpecific]
    public virtual XhtmlString MainBody { get; set; }
    
    // Shared - all languages share the same value
    // (no [CultureSpecific])
    public virtual ContentReference RelatedPage { get; set; }
    public virtual int SortOrder { get; set; }
}

3. Fallback Language

// If content does not exist in the current language:
// CMS will fall back according to configured language settings

// Configured in Admin → Languages → Language Settings
// → Enable fallback to: English
// → Or "Return empty string" if no fallback

4. Creating a Language Branch via Code

public class TranslationService
{
    private readonly IContentRepository _contentRepository;

    public void CreateLanguageBranch(ContentReference link, string language)
    {
        // Load existing (English/master)
        var masterPage = _contentRepository.Get<ArticlePage>(link);
        
        // Create language branch
        var branchPage = _contentRepository.CreateLanguageBranch<ArticlePage>(
            link, 
            new LanguageSelector(language));
        
        var writableBranch = (ArticlePage)branchPage.CreateWritableClone();
        writableBranch.Heading = "Translated heading";
        writableBranch.MainBody = new XhtmlString("<p>Translated body</p>");
        
        _contentRepository.Save(writableBranch, SaveAction.Publish);
    }
}

5. Language Routing

URL: /en/products/article
URL: /sv/produkter/artikel
URL: /de/produkte/artikel
    └── Mapped via SiteDefinition.StartPage + LanguageBranch URL segment

6. Managing Languages in Code

// ILanguageBranchRepository
public class LanguageService
{
    private readonly ILanguageBranchRepository _languageBranchRepository;

    public LanguageService(ILanguageBranchRepository languageBranchRepository)
    {
        _languageBranchRepository = languageBranchRepository;
    }

    public IEnumerable<LanguageBranch> GetEnabledLanguages()
    {
        return _languageBranchRepository.ListEnabled();
    }

    public bool IsLanguageEnabled(string languageCode)
    {
        return _languageBranchRepository.IsEnabled(languageCode);
    }
}

7. Content Translation Status

Page → Edit View → Language Selector dropdown
  → Shows all languages for current page
  → Indicators:
     ✅ Green: Translated and published
     🟡 Yellow: Draft exists but not published  
     ❌ Red: Not translated yet

Review Questions

  1. What does the [CultureSpecific] attribute do? (Property has a different value for each language)
  2. Without [CultureSpecific], what is the property? (Shared – used across all languages)
  3. What is a language branch? (A translation of a content item in a specific language)
  4. What is a fallback language? (The language displayed if content has not been translated into the current language)
  5. Which method creates a language branch in code? (IContentRepository.CreateLanguageBranch<T>())