Developer forum

Forum » Development » Current website language in API

Current website language in API

Dmitrij Jazel
Reply

Hi everyone,

This should be quite easy.

Need to know what is the way of getting the Language that website is currently using.

Thought it was in here:

Dynamicweb.Frontend.PageView.Current().Area.

But appearently it was not.

 

Tons of suggestions how to get langiage in eCommerce, but if I need to know the language of NOT eCommerce, but just the website that currently is visiting.

In global tags, noticed this: http://screencast.com/t/HcmOunVZTUU

Would love to use it, but things like: 

GetGlobalValue("Lang").ToString(); //(in front-end)

does not seem to work either.

Idealy I would like to get it through PageView object, if possible, so that I could also use it in the API when needed.

 

/Dmitrij


Replies

 
Nicolai Høeg Pedersen
Reply

Dynamicweb sets the culture to the one specified on the website properties, so you can just go for Thread.CurrentCulture.

 
Dmitrij Jazel
Reply

Hi NIcolai,

The place where I need to get this information is Global.asax.

That "Thread" object that you are using in" Thread.CurrentCulture what namespace is it? System.Threading or something else?

Another way could be (even more convenient for our implementation) would be to reach out to website properties while still in Global.asax and fetch some field values.

But "Dynamicweb.Frontend.PageView.Current().Area.Item["myvalue"]" throws null pointer exception at once. Obviously because we are so early in the lifecycle that Pageview is not yet initialised.

 

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Dmitrij

Everything in Global.asax runs before a pageview instance is at hand, so you can of course not use the pageview. Also at this stage the right thread culture has not been set as it is done by the pageview instantiation - you can find Thread culture namespace by Googling it - you should not ask me that :-).

Tell me what you want to achieve - then I might be able to give you some pointers.

BR Nicolai

Votes for this answer: 1
 
Dmitrij Jazel
Reply

That is what I thought, so thank for that info :)

 

Well I am still trying to implement the Automatic website language and Currency change in the most elegant way.

As Imar pointed out once (can't find the forum post now). he said that global.asax would be great place for that.

Well I think so to, and session start looks like a nice place to begin with.

But when I am in the session start. I don't have Pageview, and can't access the area of the site I am "landing on".

Same goes for currency actually (same problems to solve).

 

All in all Global.asax is a nice place but it also affects /Admin, I sure can avoid code via if(rawurl.contains("/admin")) but still there are many things that I would need to reach to use it properly.

 

After some testing, I can see that this works the best if I add some code in Master. instead. But I would love to find another place to have this code, as I would love to have it in custom project, instead of template files.

 

Regarding Thread culture - I will try that :)

 

/Dmitrij

 
Nicolai Høeg Pedersen
Reply

The template is the wrong place. It is executed as the very last thing.

You should use Notifications.Standard.Page.Loaded notification subscriber.

 
Dmitrij Jazel
Reply

Hi Nicolai,

Page loaded notification works really nice for this purpose. Looks really nice so far.

Thanks for help! :)

 

/Dmitrij

 

You must be logged in to post in the forum