Hi everyone,
as you might know, one of the problems in ASP.NET Web API 2 is that you don't get access to HttpRequestMessage inside your data validators and because of this you cannot get incoming HTTP headers where client (for example, browser or mobile app) sends information about preferred user culture (for example, custom "culture" or standard AcceptLanguage headers).
BTW, an alternative way of passing user culture into validators could be setting current thread culture in action filter before validation occurs or adding thread data (for example, using Thread.SetData(...), ThreadStaticAttribute or ThreadLocal<T> type). But I would prefer not to do it.
So, basically the situation is the following: you can write your custom validators but you cannot localize error messages inside Validate(ModelMetadata, object) method. Terrible!
As always there is an ugly way of passing HttpRequestMessage into validators but it requires some copy-pasting from ASP.NET Web Api source code to make it working right (which makes it less maintainable).
I checked the implementation in new ASP.NET vNext, it does not seem to be any better from current (if I didn't miss something). So, migration to new ASP.NET version will not solve my problem.
May be somebody knows a better way to localize errors in Web API 2? How do you do it?