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
When I'm retrieving data within a API method, I have trouble getting the content for the correct culture.
It seems to completly ignore the url from which the API function is run and instead uses the default culture.
When trying to set the culture myself, or getting the correct language variant I get stuck.
string culture = "nl";
var ticketsFeed = GetRootElement(); // this works
// HACK TO GET THE RIGHT CULTURE, seems it doesn't work
System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
var umbracoFeedItems = ticketsFeed.Children(culture) // looks like culture is ignored
.Where(n => n is FeedItemtickets)
.Select(n => (FeedItemtickets)n);
var test = umbracoFeedItems.First();
var test2 = test.HasCulture("nl"); // true, yes I have it I'm just not giving it to you
var test3 = test.GetProperty("Summary"); // Gives English text instead of Dutch
var test4 = test.Summary // Also the English text instead of Dutch
// no overload available like: test4.GetProperty("Summary", culture);
Anybody any idea on how to fix this ?
To answer my own question:
var existingPublishedItem = umbracoFeedItems.Where(n => !String.IsNullOrWhiteSpace(n.UniqueId) && n.UniqueId == rawItem.ProductId).First();
var existingItem = contentService.GetById(existingPublishedItem.Id); // via injection I got a reference to the concentService
string summary = existingItem.GetValue<string>(FeedItemTickets.GetModelPropertyType(x => x.Summary).Alias, culture);
Wish I could have use existingPublishedItem.Summary instead of this semi-strongly-typed solution in this multilingual scenario.
How about injecting IVariationContextAccessor and setting the culture there before you fetch any content? E.g.
_variationContextAccessor.VariationContext = new VariationContext("nl");
// get content here
Thanks Johan, that's looks like a much better solution then what I came up with.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted