Skip to main content

Outline

At a glance
  • What this covers: Reading language branch definitions (which languages exist, active/master status) using ILanguageBranchRepository.
  • What it is not: Content translation itself - localized content is handled via IContentLoader/IContentRepository with CultureInfo and loader options.
  • Common use cases: language selectors, reporting, automation that iterates through configured languages, sanity checks for environment parity.
  • Key reminder: language branches define “available languages”; content versions define “localized content.”


Introduction

Optimizely CMS 12 is designed for multilingual websites, where the same content item can exist in multiple language versions. Editors typically manage language configuration in Admin views, but developers still need to understand how language branches are represented in the platform - especially when building custom language pickers, running localization audits, or implementing automated workflows that iterate over all configured languages.

This page focuses on the developer-facing model: what a LanguageBranch is, how to read language branches through ILanguageBranchRepository, and how that relates to loading and saving content in specific languages.



1. Core concepts: what a language branch represents

A language branch is Optimizely’s representation of a configured language for your site(s). It describes the language as a configuration entity (culture, display name, active/master status), not the translated content itself.

Key properties you’ll commonly inspect include:

  • Culture: the CultureInfo (for example en-US, sv-SE).
  • Name: display name of the language branch.
  • ID: internal identifier.
  • IsActive: whether the branch is enabled for use.
  • IsMaster: whether the branch is the master language.

Administrators typically manage branches under CMS admin configuration views (for example, language branch management and website language mappings). From code, you usually treat branches as read-mostly configuration.



2. Obtaining ILanguageBranchRepository

ILanguageBranchRepository provides access to configured language branches. As with other Optimizely services, use dependency injection.

using EPiServer.DataAbstraction;

public class LanguageService
{
    private readonly ILanguageBranchRepository _languageBranchRepository;

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


3. Scenario 1: Listing all configured language branches

Listing language branches is useful for building a custom language selector, generating localization reports, or validating that environments (Integration/Preproduction/Production) share the same configured languages.

using System;
using System.Linq;
using EPiServer.DataAbstraction;

public class LanguageService
{
    private readonly ILanguageBranchRepository _languageBranchRepository;

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

    public void ListAllBranches()
    {
        var branches = _languageBranchRepository.ListAll();

        if (!branches.Any())
        {
            Console.WriteLine("No language branches configured.");
            return;
        }

        Console.WriteLine("Configured language branches:");
        foreach (var b in branches)
        {
            Console.WriteLine($"- {b.Culture.Name}");
            Console.WriteLine($"  Name: {b.Name}");
            Console.WriteLine($"  ID: {b.ID}");
            Console.WriteLine($"  Active: {b.IsActive}");
            Console.WriteLine($"  Master: {b.IsMaster}");
        }
    }
}
Expand: Typical “branch list” pitfalls
  • Configured vs enabled: a branch can exist but be inactive; don’t assume “listed” means “usable.”
  • Environment drift: language configuration can differ across environments if not governed (especially in long-lived projects).
  • Site mapping: multi-site setups may use only a subset of branches per site; branch existence isn’t the same as site availability.


4. Scenario 2: Getting a specific language branch

You may need to retrieve a particular branch to check whether it’s active, whether it’s the master language, or to safely obtain a CultureInfo object for downstream content operations.

using System;
using System.Globalization;
using EPiServer.DataAbstraction;

public class LanguageService
{
    private readonly ILanguageBranchRepository _languageBranchRepository;

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

    public LanguageBranch GetByCultureName(string cultureName)
    {
        try
        {
            var culture = CultureInfo.GetCultureInfo(cultureName);
            var branch = _languageBranchRepository.Get(culture);

            Console.WriteLine($"Found branch: {branch.Culture.Name} (Active: {branch.IsActive}, Master: {branch.IsMaster})");
            return branch;
        }
        catch (CultureNotFoundException)
        {
            Console.WriteLine($"Invalid culture: '{cultureName}'.");
            return null;
        }
    }

    public LanguageBranch GetById(int id)
    {
        var branch = _languageBranchRepository.Get(id);
        if (branch == null)
        {
            Console.WriteLine($"No language branch found for ID {id}.");
            return null;
        }

        Console.WriteLine($"Found branch: {branch.Culture.Name} (Active: {branch.IsActive}, Master: {branch.IsMaster})");
        return branch;
    }
}


5. About enabling/disabling language branches programmatically

Developers often ask whether they can “toggle” IsActive through code. In practice, language branch activation is usually treated as an administrative configuration concern, managed through CMS admin views. Changing active languages affects editorial workflows, language routing, and fallback behavior - so governance typically expects it to be controlled, reviewed, and consistent across environments.

If you truly need programmatic management, treat it like infrastructure/configuration automation: tightly restricted, audited, and validated in non-production. For most applications, the repository is used primarily for reading the language configuration.

Practical guidance

If your automation needs “the list of usable languages,” filter the repository results by IsActive and keep activation changes in the admin/config layer.



6. Working with localized content (where ILanguageBranchRepository fits)

Language branches define what languages exist. Localized content versions are handled through IContentLoader and IContentRepository, typically by specifying a CultureInfo or language loader options.

using System.Globalization;
using EPiServer;
using EPiServer.Core;
using EPiServer.Globalization;

public class LocalizedContentExample
{
    private readonly IContentLoader _contentLoader;

    public LocalizedContentExample(IContentLoader contentLoader)
    {
        _contentLoader = contentLoader;
    }

    public void LoadInSpecificLanguage(ContentReference contentLink)
    {
        var sv = CultureInfo.GetCultureInfo("sv-SE");
        var swedishVersion = _contentLoader.Get<PageData>(contentLink, sv);

        var currentVersion = _contentLoader.Get<PageData>(contentLink, ContentLanguage.PreferredCulture);
    }
}

A typical pattern is: query language branches for what’s configured, decide which cultures are valid for the current site context, then load content in the selected culture.



7. Best practices for language management

  • Keep language setup consistent across environments: treat it like configuration, not “random admin clicks.”
  • Implement sensible fallback rules: define expected behavior when a translation is missing.
  • Separate concerns: UI localization (resource strings) is different from content localization (language versions).
  • Be explicit in code: when language matters, pass a CultureInfo rather than relying on request defaults.
  • Audit “active languages” regularly: inactive branches can linger and confuse tooling and editors.

Conclusion

ILanguageBranchRepository is the developer entry point for understanding which language branches are configured in an Optimizely CMS 12 instance. While it’s most often used for reading configuration (listing branches, checking active/master status), it plays an important supporting role in multilingual solutions: it helps you decide which cultures are valid inputs, and it enables automation to operate consistently across all configured languages. Localized content work still happens through IContentLoader/IContentRepository by targeting the right CultureInfo.