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:
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:
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 www.mysite.com/nl-NL 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
>So if a user browser to www.mysite.com/nl-NL i want to get the value 'nl-NL', ...
How about <html lang="@Html.ViewContext.RequestContext.RouteData.Values["language"]"> ?
It seems RequestContext.RouteData.Values["language"] gives the same values as ContentLanguage.SpecificCulture.Name, thanks though.