May I ask what your scenario for wanting to fetch the value is? What do you need to achieve by looking at the lang attribute? Is it some script behaviour, CSS or something that involves the server?
The proposed solution is good if you want to manipulate the DOM but if you need to render something serverside-wise you need another approach.
Ideally, you have a MasterLayout.cshtml file that actually writes that attribute (by looking up the current culture) if your site is multilingual. So whichever method you're using there should be applicable in any other Razor view.
I'm an XSLT guy, so I'm doing this a little bit different, but I'm sure there is a way in C# to get the current culture's language code.
What a fantastic community with so many helpful people :-)
I have an Umbraco solution where I need to have the site in 2 languages. The pure translation part with Umbraco Dictonary Items is easy. But I have to hide some parts of the page when the language shifts. As Dennis pointed out one would do this with JavaScript. However it could be fine to use it in Razor as well like this
RAZORSCRIPT:
var myLanguageVariable = get the current language
if(myLanguageVariable == "en") {... show this part of the page.}
if(myLanguageVariable == "de") {.. don't show this part of the page }
Getting the content of <html lang> tag in Umbraco razor
Hi. How can I get the content of the tag <html lang="en"> dynamically? I want to have a tag like this
var languageCulture = "en" in case of the html lang tag equals "en" and so on! What razor can I use to get that content?
Any help highly appreaciated :-)ยจ
//Lars
Hi Lars,
You can use jQuery for that. You can't use razor for get that, Razor is for setting that markup.
Thanks
Hi Lars and welcome to our,
As Alex says you can use jQuery to get the value of the langague attribute on the html tag.
Hope this helps,
/Dennis
Hi Guys
I thought that I could get in Razor. So thank you for your help :-)
//Lars
Hi Lars
May I ask what your scenario for wanting to fetch the value is? What do you need to achieve by looking at the lang attribute? Is it some script behaviour, CSS or something that involves the server?
The proposed solution is good if you want to manipulate the DOM but if you need to render something serverside-wise you need another approach.
Just curious :)
/Jan
Hi all,
Ideally, you have a MasterLayout.cshtml file that actually writes that attribute (by looking up the current culture) if your site is multilingual. So whichever method you're using there should be applicable in any other Razor view.
I'm an XSLT guy, so I'm doing this a little bit different, but I'm sure there is a way in C# to get the current culture's language code.
/Chriztian
What a fantastic community with so many helpful people :-)
I have an Umbraco solution where I need to have the site in 2 languages. The pure translation part with Umbraco Dictonary Items is easy. But I have to hide some parts of the page when the language shifts. As Dennis pointed out one would do this with JavaScript. However it could be fine to use it in Razor as well like this
RAZORSCRIPT:
var myLanguageVariable = get the current language
if(myLanguageVariable == "en") {... show this part of the page.}
if(myLanguageVariable == "de") {.. don't show this part of the page }
--------------
// Lars
Hi Lars
I'd say that if you need to hide something based on language then you should go for a serverside solution rather than a client side solution.
As Chriztian also points out it really should be set in the master template based on the site culture.
I'm not too experienced dealing with it in Razor either but perhaps you can find some inspiration in this post http://stackoverflow.com/questions/19495980/get-culture-display-name-in-its-language or simply googling a bit more about to get the culture name using Razor :)
/Jan
Thanks, Jan. It works with JQuery
//Lars
is working on a reply...