Hi– I'm planning to handle server side localization for error strings etc. based on the “Accept-Language” header, by setting the CurrentUICulture based on that header, but apparently it doesn’t flow though the async calls, below is a sample code to illustrate the problem, is there any default way of handling the localization for async calls?
public async Task<HttpResponseMessage> GetAsync()
{
//set the current ui culture, to say "fr-FR", based on "Accept-Language" header
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("**fr-FR**");
var task = httpClient.PutAsync(endpoint, content)
//do some processing
var res = await task;
var culture = Thread.CurrentThread.CurrentUICulture.Name; **//ITS NOT necessarily fr-FR**
//do some more processing
//and handle localizations etc.
return res;
}
I'm looking for a cleaner/seamless way of handling localization for cases where there are real async operations esp. for the code following the await call
Edit: replaced Task.Run() with httpClient.PutAsync for clarity