deMD / UmbracoContentApi

A package that enables easy integration of Headless Api functionality into your project.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Resolve content for a given culture

ksolberg opened this issue · comments

Hi, first of all - thanks for a nicely crafted component!

I can't seem to identify how to resolve content for a specific culture.

commented

Resolving content for a specific culture is pretty narly in any api due to the nature of how Umbraco handles it. The way I have found it working is by manually setting the culture of the variationcontextaccessor.

private readonly IVariationContextAccessor _variationContextAccessor;

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

public ContentModel GetContent(string culture)
{
    if (!string.IsNullOrEmpty(culture) && _variationContextAccessor.VariationContext.Culture != culture)
    {
        _variationContextAccessor.VariationContext = new VariationContext(culture);
    }
			
	...
}

This way the content will be returned in the proper culture.