Good way to changing language resources dynamically by request

前端 未结 1 1592
忘了有多久
忘了有多久 2021-02-15 19:58

I have an ASP.NET Web API application which should react to user\'s Accept-Language header appropriately.

Currently, the strings are stored in the resx and accessed in c

相关标签:
1条回答
  • 2021-02-15 20:27

    From reading your question, I don't see anything that ASP.NET doesn't offer automatically. You can configure your ASP.NET (whether WebForms or MVC) to use the accept-language request header and set the appropriate UICulture (which will impact which satellite assembly is loaded by ResourceManager) and Culture (which will impact locale-dependent formatting and parsing such as dates and numbers) appropriately.

    To configure your app to use the accept-language list to set both UICulture and Culture for each request, (as per this MSDN page), configure your web.config like this:

    <globalization uiCulture="auto" culture="auto" />
    

    There is also an equivalent configuration setting per page.

    Then, as per the Resource Fallback process, if your app includes a satellite assembly for the matching culture (or, failing that, its parent neutral culture), it will be used by the Resource Manager. If not, then your default resources will be used (English if that's your base language).

    0 讨论(0)
提交回复
热议问题