Trouble getting CurrentLanguageBranch in CMS5



I'm trying to get the current languagebranch in CMS5. In 4.61 this was done using LanguageContext.Current.CurrentLanguageBranch. In CMS5 I'm doing this in the following way:


In our EPiServer-site we have configured the languages "NO" and "EN", which are selectable from the list in admin-mode. The problem is that when "NO" is selected, the CultureInfo.CurrentCulture will be "nb-NO". The LanguageBranch.Load method does not find the LanguageBranch, and returns null. The same is the case when "EN" is selected, then the CultureInfo.CurrentCulture becomes "en-US". This seems strange, since "EN" can be selected as a language in EPiServer. Changing the LanguageID from "EN" to "en-US" is not possible in admin-mode.

Does anyone know how this can be solved? Is there another way to get the current languagebranch in CMS5?


#Roy Are

Apr 17, 2009 8:35

Can you try CultureInfo.CurrentUICulture instead? That one should be just "en".


Apr 17, 2009 18:57

That would work for the EN-case. However, we also have "nn-NO" (nynorsk) enabled as a language. The problem is that the CurrentUICulture returns "NO" for both NO (which is really nb-NO) and nn-NO. I need to get the exact languagebranch from EPiServer in order to separate these languages. So using CurrentUICulture is unfortunately not a solution.

Apr 20, 2009 9:35

Try CurrentPage.LanguageBranch it returns the culture as set in admin-mode. I use it for "en-GB" for example and works fine.


Apr 20, 2009 13:48

I have tried using CurrentPage.LanguageBranch. It returns the LanguageId in the format I need, but there is a problem when fallback-languages are enabled. The languageId of the current page is returned. If this page is shown in a fallback-language, the returned value is not the same as the CurrentLanguageBranch selected by the user.

Example: The user has chosen to view the site in language "nn-NO" (nynorsk). A page does not exist in this language and is shown in its fallback-language "NO" (norsk bokmaal). Then CurrentPage.LanguageBranch will return "NO", but the CurrentLanguageBranch should still be "nn-NO". CultureInfo.CurrentUICulture also return "NO" in this case. If I use CultureInfo.CurrentCulture I get the correct "nn-NO" in this case, but this will be wrong when "NO" is chosen as a language. Then it will return "nb-NO" (not recognized as "NO" from admin-mode") as described in my original post. In 4.61 LanguageContext.Current.CurrentLanguageBranch returned the correct value I was looking for.

Apr 21, 2009 9:16
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.