Is current user language stored in session?

Vote:
 

Hey guys

Another globalization/language question from me!

I know the user is able to request a globalized page in several ways:
- through URL, e.g. /en-gb/Default.axpx
- through URL parameter, e.g. /Default.axpx?epslanguage=en-gb
- setting epslanguage cookie with language

How do I retrieve the current users selected language? So I have to store this in session variable myself, or is there a episerver method that will give me this? I know I can use CurrentPage.LanguageBranch, but I need this information in a ashx handler, there is no current page context.

Hope that makes sense :/

thanks

#45822
Nov 18, 2010 18:01
Vote:
 

On the Request object, there's a UserLanguages array.  It's an array of language codes as strings.  Is this what you want?

#45825
Nov 18, 2010 18:19
Vote:
 

Thanks for the reply, but unfortunately the only UserLanguage strings always seems to return en-gb and en;q=0.5 (assuming System.Web.HttpRequest object... This is regardless of which language I go to (e,g, "/" [root], Russian [ru-ru] or english [en-gb].

I would have expected some sort of server session token that stores which language the last page request by the user was, and not have to send this with every request (in this particular instance I'm writing an image http handler and so it is definately not possible).

 

thanks

#45914
Nov 22, 2010 17:11
Vote:
 

If you are doing the work in a handler then you will need to revert to some URL parsing and using the EPiServer language manager to look up the language. Something like this will do the trick:

UriBuilder builder = new UriBuilder("http://www.fullurl.com/en/content/");
string langSegment = builder.Uri.Segments[1].TrimEnd("/".ToCharArray());
LanguageNode node = LanguageManager.Instance.GetLanguages().Where(lang => lang.Name == langSegment).ToList()[0];
    
#45922
Nov 22, 2010 19:49
Vote:
 

Ps since you are using this for an image handler you could always pass the current URL on the querystring to the handler and use the code I supplied above.

#45924
Edited, Nov 22, 2010 20:38
Vote:
 

Thanks for the info and code snippet David. I was messing around with something similar yesterday.

I'm not sure I can pass the URL on the handler unfortunately (at least I'm not sure how). I've set up a httpHandler in web.config for all files in my "images/global" folder.

The idea was that any image in the folder would get served through the handler. That way I could use the same CSS and markup for all my sites, since it is only the images with hardcoded text that change for each locale. My folder structure would comprise of something like "images/global/en-gb/image.png", "images/global/es-es/image.png" etc etc. A request for "images/global/image.png" would use the current session locale to serve the correct image. If that folder was not present then I could use the fallback language (set up in episerver) to serve that instead.

I think I may just store the locale in session from my base/master page and continue that way.

 

thanks

Kam

#45946
Edited, Nov 23, 2010 11:59
* 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.