Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Is there a way to properly localize Web API controllers? It would be useful if we could somehow fetch the current visitor's locale, and use this locale to set the thread's UI culture (i.e. for using dictionary).
For now I have worked around by providing the culture via query string, and an action filter:
public class LocalizableByCultureParameterAttribute : ActionFilterAttribute
public override void OnActionExecuting(HttpActionContext actionContext)
var queryStrings = actionContext.Request.Properties["MS_QueryNameValuePairs"] as IEnumerable<KeyValuePair<string, string>>;
if (queryStrings != null && queryStrings.Count(q => q.Key == "culture") == 1)
var culture = queryStrings.Single(q => q.Key == "culture").Value;
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
catch (CultureNotFoundException cnf)
LogHelper.Error(typeof(LocalizableByCultureParameterAttribute), "Culture not found", cnf);
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted