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;
- Developing with Page Type Builder – Inheritance and Specifying Property Types
- Introducing EPiMVP – A Framework for using Web Forms MVP with EPiServer CMS
- How to create a custom EPiServer property
- Developing with Page Type Builder – Advanced Property Access
- EPiServer integration patterns
- Creating a Custom EPiServer Property with a Custom Class as Value
- The EPiServer CMS Output Cache Explained
- Sweet EPiServer Templating with TypedPageList