AI OnAI Off
If I remeber correctly API:s typically run in a separate thread thus this issue.
I usually implement an ActionFilterAttribute fetching the language cookie that way, from there on you can set the thread cultures.
Hi did you check your localization settings in startup.cs ?
var supportedCultures = new[] { "en-US", "fr-FR", "de-DE" };
var localizationOptions = new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("en-US"),
SupportedCultures = supportedCultures.Select(c => new CultureInfo(c)).ToList(),
SupportedUICultures = supportedCultures.Select(c => new CultureInfo(c)).ToList()
};
app.UseRequestLocalization(localizationOptions);
Hi all
We have an API hosted on Optimizely 12, which we call from our Javascript frontend. In general it works just fine. However culture is not set correctly in our API Controller. When looking at Thread.CurrentThread.CurrentUICulture, we can see that culture is "en". We have not enabled "en" on our Optimizely site, but instead we have enabled "en-US" for different reasons.
How are you handling language and culture in your API calls?
I have found this thread in the forum, but as far as I can see, it never reached an answer:
https://world.optimizely.com/forum/developer-forum/cms-12/thread-container/2022/9/best-practice-for-fetching-language-context-in-an-api-controller/
It looks as if the Optimizely Content Delivery API relies on the Accept-Language header being set correctly. I think that is a good option, and we have tried to set this header in our API calls. It is not picked up automatically by our API Controller.
How do I programatically set language in a way that Optimizely accepts?
Thank you for your help.
Regards
Anders