Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
In a project im working on, we have at the moment 4 language variants with sv-se as the default.
If im on the english variant of the site and use ajax to get data from the controller i allways get the Swedish version back.
Is there someway to get the culture specific version of a document with the culture specific properties?
Right now im using var model = Umbraco.Content(id);.
var model = Umbraco.Content(id);
Thanks in advance.
As you call Umbraco.Content(id) you are actually getting the published content back with all the cultures in it.
when you call model.Value("someProperty") that will be returning the default (so Swedish in your case) but you can call it with the culture name to get the other language versions.
var myValue = model.value("someProperty", cultureName)
from an ajax call the controller won't know what language you want so you will need to pass that as part of your method name so a method like this should work* :
public string GetSomething(int id, string culture)
var content = Umbraco.Content(id);
return content.Value<string>("someValue", culture);
*with null checks and all the other stuff
Thanks for the reply.
Is it possible the get the published content back in a specific culture?
I don't think you can - the PublishedContent item contains all the variant values when you get it.
You might be able to do something by setting the thread culture so that the default calls to model.Value() return in the culture of the executing thread, but I am not 100% sure that would work, or it wouldn't cause you other issues down the line.
Ah okay, the other approach works just fine :).
Thanks for the help
Since Umbraco 8.1 is released with changes for better Multilingual support. Is there a better way to get language specific values now instead of having to rely on magic strings?
Bit late to the party here but yes, you can avoid magic strings by using an expression:
content.Value(x => x.SomeValue, culture);
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted