3

I have biligngual website with German language set as default language and I am trying to get English content nodes from my SurfaceController like this:

Umbraco.Content(ID);

And i have tried to change curent culture like this:

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

But without success.

Josip Pavlović
  • 167
  • 1
  • 12
  • Have you looked at the new language variants in V8? https://our.umbraco.com/documentation/Getting-Started/Backoffice/Variants/ - and here's how you do it in the frontend: https://our.umbraco.com/documentation/Getting-Started/Design/Rendering-Content/ – Jannik Anker Sep 23 '19 at 10:54
  • I have found the answer on Umbraco forum , after days of searching – Josip Pavlović Sep 23 '19 at 12:39

1 Answers1

9

Found the answer:

private readonly IVariationContextAccessor _variationContextAccessor;

public ContentApiController(IVariationContextAccessor variationContextAccessor)
{
    _variationContextAccessor = variationContextAccessor;
}

public IHttpActionResult Get(int id, string culture)
{
    _variationContextAccessor.VariationContext = new VariationContext(culture);
    var cnt = Umbraco.Content(id);
    return Ok(cnt.Name);
}
Josip Pavlović
  • 167
  • 1
  • 12
  • Thank you. I don't know, why this has so little upvotes - this is a big and common issue, and your answer is perfectly working. – Florian D. Jul 10 '20 at 22:48