Problems getting language of page



On our website we need to know the language of the current page for a various of situations, like fetching products from a subsystem in the correct culture etc.

We currently use the following code for fetching the current page language:



We have english as our main language, and a bunch of other languages like dutch who have english as their fallback language. We use EPiServer 7.1 with patch 4.

Getting language outside of CMS (Seems incorrect, but works how we want it)

Suppose i do the following:

  1. Create a new page in english
  2. Publish that page
  3. Do not translate, exit CMS
  4. Browse to the dutch version of that page (which will fallback to english)

What value should ContentLanguage.SpecificCulture.Name have on this dutch page?
In our case we get 'nl-NL', which is dutch.
Now since the page is actually showing english content (fallback), shouldn't the value be 'en-US'?

Getting language in CMS (Seems correct, but doesn't work the way we want it)

Suppose i do the following:

  1. Open CMS in dutch site/language
  2. Browse to page you created in the steps above

What value should ContentLanguage.SpecificCulture.Name have now?
In our case we get 'en-US', which is english.
Now this is a different value then before, whilst it's the same page.
In this case, since the english fallback language is used, the value sounds correct to me.

In short: Outside of the CMS ContentLanguage.SpecificCulture.Name will return the same language as specified in the url, while in CMS the actual language of the content will be returned.

What we want

We would like a solution where we always get the language that the user requested, no matter if there is content for that language and/or if the user is editing in CMS.
So if a user browser to i want to get the value 'nl-NL', and if a user is editing that same page in CMS for the dutch site/language i also want to get the value 'nl-NL'.

I already found functions to retrieve things like the current EPiServer CMS language branch (HttpContext.Request.Cookies["editlanguagebranch"]) or whether a page is in editmode (PageEditing.PageIsInEditMode), and could build my own logic on top of functions like these to fix my problem, but i much rather have an elegant solution.

Also, you have this thing called ViewSettings in CMS where you can set the current language, but it's not the same as sites. What's the difference between those two? How to deal with these ViewSettings in correlation with the other language things described above?



Any information on this subject is greatly appreciated, thanks in advance!

Greetings, Martijn van der Geest

Oct 08, 2013 16:56

>So if a user browser to i want to get the value 'nl-NL', ...

How about <html lang="@Html.ViewContext.RequestContext.RouteData.Values["language"]"> ?

Edited, Oct 08, 2013 18:40

It seems RequestContext.RouteData.Values["language"] gives the same values as ContentLanguage.SpecificCulture.Name, thanks though.

Oct 09, 2013 10:25
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.