Need to figure out the actual language context we’re in, disregarding fallback or replacement languages in EPiServer CMS? The PreferredCulture property of the ContentLanguage class to the rescue!
Sometimes we need to figure out what language context we’re in in EPiServer. If we’re coding a template we may be tempted to look at the LanguageBranch property of the CurrentPage property. However, in other situations that may not be available and that won’t actually tell us what language context we’re in but what language branch the current page is loaded from. In most situations those two values will be the same, but if the page has fallback or replacement languages configured it won’t.
To figure out the actual language context we’re in, disregarding fallback or replacement languages, we can instead use the static PreferredCulture property of the ContentLanguage class located in the EPiServer.Globalization namespace. Like this:
//using EPiServer.Globalization; CultureInfo currentCulture = ContentLanguage.PreferredCulture; string languageBranch = currentCulture.Name;