Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServiceStack localized message text

Is there a way to set the culture of error messages coming back from SS via the incoming request from the Client? Can I set the culture of a JSONService client in some fashion and then have SS respond with message text in that culture.

like image 335
etechpartner Avatar asked Jul 17 '13 19:07

etechpartner


1 Answers

Yes, you can set the current culture per request in a pre-request filter:

host.PreRequestFilters.Add((httpReq, httpResp) =>
{
    Thread.CurrentThread.CurrentUICulture = DefaultCulture;

    if (httpReq.Headers.AllKeys.Contains(HttpHeaderKeys.AcceptLanguage))
    {
        var cinfo = new CultureInfo(httpReq.Headers[HttpHeaderKeys.AcceptLanguage]);
        if (new ResourceManager(typeof(ResourceFile)).GetResourceSet(cinfo, false, false) != null)
            Thread.CurrentThread.CurrentUICulture = cinfo;
    }
});
like image 111
jruizaranguren Avatar answered Oct 01 '22 04:10

jruizaranguren