Just out of curiosity - why do you only pick the two initial letters ("da" instead of the complete "da-DK")?
I know danish doesn't exist in any other versions, but e.g. English has more than a couple of different versions, so wouldn't you ideally just include them, if the particular site has a specific version?
Oh yes - curiosity is great and I see your point :) I'm however following the w3 specification on language tags and since this particular site isn't going to have multiply regional versions in the same language - it's using the shortest possible version "da", "en" etc.
The golden rule when creating language tags is to keep the tag as
short as possible. Avoid region, script or other subtags except where
they add useful distinguishing information. For instance, use ja for
Japanese and not ja-JP, unless there is a particular reason that you
need to say that this is Japanese as spoken specifically in Japan.
But I now realized that Umbraco has region-less languages - both Danish (da-DK) and Danish (da) are available in the language selection list. Dammit! This means the substring method is unnecessary. I'll be updating the answer above. Thanks for the curiosity Chriztian ;)
Well, I actually just stumbled upon it on a project where I needed the same thing and it's seems to be a very native thing - I just googled Razor C# culture.
Not everything is in the cheat-sheet but is just native C# stuff.
I see - Razor is still very new to me, so I didn't even think this could be a native thing :)
Btw: I marked my own complete answer as Solved for others who might be having a simular question. I now realise that this gave my karma a good boost :( Think I misinterpreted the function since it was you who solved the puzzle :/
Getting the language property with Razor
Hi all,
How do I get the language id (chosen from culture/hostnames in the content tree) into the html lang attribute with Razor?
Thanks
Hi Mathias,
I can get the culture alias with this code:
Maybe this can help you?
Best,
Sören
Thanks, but I'm getting an error :/
Object reference not set to an instance of an object.
Hi Mathias,
Try to see my comment in this: https://our.umbraco.org/forum/using/ui-questions/57860-Getting-the-content-of-html-lang-tag-in-Umbraco-razor, you can get the language property with jQuery.
Hope this helps,
/Dennis
Hi Mathias
If I understand you correctly you want to populate the lang attribute with the chosen culture?
If you want to render it then try simply writing
lang="@Culture"
.Does that work for you?
/Jan
Hi Jan,
Ah yeah I totally forgot this option :-) on how you can set the language property.
/Dennis
Hi Jan,
great :-) This is very simple!
Sören
Awesome! Now I feel kind of stupid, how did I miss @Culture :/ The complete solution for me was:
@jan where can I find these properties? as they don't appear on the cheat-sheet.
Thanks everybody!
Hi Mathias,
Just out of curiosity - why do you only pick the two initial letters ("da" instead of the complete "da-DK")?
I know danish doesn't exist in any other versions, but e.g. English has more than a couple of different versions, so wouldn't you ideally just include them, if the particular site has a specific version?
/Chriztian
Oh yes - curiosity is great and I see your point :) I'm however following the w3 specification on language tags and since this particular site isn't going to have multiply regional versions in the same language - it's using the shortest possible version "da", "en" etc.
But I now realized that Umbraco has region-less languages - both Danish (da-DK) and Danish (da) are available in the language selection list. Dammit! This means the substring method is unnecessary. I'll be updating the answer above. Thanks for the curiosity Chriztian ;)
Hi Mathias
Happy you figured it out :)
Well, I actually just stumbled upon it on a project where I needed the same thing and it's seems to be a very native thing - I just googled Razor C# culture.
Not everything is in the cheat-sheet but is just native C# stuff.
/Jan
I see - Razor is still very new to me, so I didn't even think this could be a native thing :)
Btw: I marked my own complete answer as Solved for others who might be having a simular question. I now realise that this gave my karma a good boost :( Think I misinterpreted the function since it was you who solved the puzzle :/
(Don't worry about "solving" your own questions - you won't actually get that Karma-boost. It just looks like it :-)
Hi Mathias
Don't worry about that - If people go straight to your answer they still get a good solution.
Yeah that's the thing with Razor...basically it's a subset of C#...so much C# stuff will just work :)
/Jan
is working on a reply...