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.
e.g
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* :
[HttpGet]
public string GetSomething(int id, string culture)
{
var content = Umbraco.Content(id);
return content.Value<string>("someValue", 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.
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?
UmbracoApiController and language variants
Hi,
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);
.Thanks in advance.
Hi,
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.
e.g
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* :
*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?
Hi
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.Hi,
Ah okay, the other approach works just fine :).
Thanks for the help
Cheers
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:
is working on a reply...