Developer forum

Forum » Development » User selectable language

User selectable language

Jon Lennryd
Reply
Hello,
I would like the user to be able to select his preferred language.

My current solution redirects the user upon login to a landing page in his preferred language. This is working, but when I later try to get the area language, it is pointing on another language.

Example:
PageView.Current().Area.get_Value("areaecomlanguageid");

I expected it to return the ecom language id of the current page. Instead it is returning 'LANG2' for no obvious reason.

I tried to set the language with
PageView.Current().Area.set_Value(), but this does not work.

As the site must handle both logged in users and anonymous users, I cannot fetch the preferred language on each page load.

Thank's for any help!

Replies

 
Nicolai Høeg Pedersen
Reply
Use eCommerce.Common.Context.Language or eCommerce.Common.Context.LanguageID
 
Jon Lennryd
Reply
Hello Nicolai, I tried your idea, but the code below still returns the 'old' language id after a page reload:

            PageView currentView = PageView.Current();
            DebugMessage("Current language: " + (string)currentView.Area.get_Value("areaecomlanguageid"));

I want the area/website module to understand that I want to 'enter' the, in this case, Swedish area.
 
Jon Lennryd
Reply
But as far as it concerns eCommerce, yes, your code above is working.
 
Nicolai Høeg Pedersen
Reply
You are asking for the property "areaecomlanguageid" which is the default ecommerce language for that area. That value will never change unless you do it from administration. Changing it affects all users on that area.

Context.LanguageID is the ecommerce language of the current user in the current context.

So - what are you actually trying to achieve? Change the eCommerce language or the website language? If it is the latter, redirect to another areaid.

 
Jon Lennryd
Reply
I try to change the website language. So how do I redirect to another areaid?

And when I have redirected to another areaid, does the property "areaecomlanguageid" change accordingly? If not, which property should I look for?

 
Jon Lennryd
Reply
Sorry, I was a bit unclear. I understand now what you are saying about the 'areaecomlanguageid'. It's fine the way it is, the connection between eCommerce and Area/Website is working fine.

What I want to do is simply to change the website language. I tried to redirect user to a page into the area/website, which works. What I can't seem to find out is where I should look to find the current area/website id? Since 'areaecomlanguageid' is wrong, which property should I look for?

Procedure:
1. Redirect user to a page in the new area/website.
2. On the new page I have a module. This module wants to know which area/website is the current. How do I get this?

 
Nicolai Høeg Pedersen
Reply
Pageview.Current.Area.ID contains the ID of the website/area
Pageview.Current.Area.get_Value("AreaCulture") contains the culture as set in regional options under website properties.

 

You must be logged in to post in the forum