Resolve content for a given culture
ksolberg opened this issue · comments
Kenneth Solberg commented
Hi, first of all - thanks for a nicely crafted component!
I can't seem to identify how to resolve content for a specific culture.
deMD 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.