[英]How to implement localization using ASP.NET Web API
I am currently developing a Web API using ASP.NET. 我目前正在使用ASP.NET开发Web API。 The Web API will send a text messages to the customers around the world.
Web API将向世界各地的客户发送文本消息。 I want to implement a localization in my Web API so the text message that will going to send to the customers are based on their language and country.
我想在我的Web API中实现本地化,因此将要发送给客户的文本消息基于他们的语言和所在国家/地区。 Where do I start to accomplish this?
我应该从哪里开始做到这一点? Thanks.
谢谢。
As mentioned, in comments, the question seems to be too broad. 如前所述,在评论中,这个问题似乎太广泛了。 There can be many right answers.
可能有许多正确答案。 Here is my attempt to give one perspective on how this issue can be resolved.
这是我对如何解决此问题的一种看法。
From design perspective, I think you need to consider one thing - localization should be implemented in the UI layer, not in API layer. 从设计角度来看,我认为您需要考虑一件事-本地化应该在UI层而不是API层中实现。
The UI layer should have localization (resx) files which includes different messages to be shown to the user. UI层应具有本地化(resx)文件,其中包含要显示给用户的不同消息。
The API should return a special object which has only error code and other error properties but not error message. API应该返回一个特殊对象,该对象仅具有错误代码和其他错误属性,而没有错误消息。
The UI layer can then parse the reply to see if there is any error code in API response. 然后,UI层可以解析回复以查看API响应中是否有任何错误代码。 If there is, then UI can have logic to convert error code to appropriate resx string based on current culture of the UI application.
如果存在,则UI可以具有根据UI应用程序的当前区域性将错误代码转换为适当的resx字符串的逻辑。 This resx string then should be displayed to the user.
然后,此resx字符串应显示给用户。
I hope this helps you. 我希望这可以帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.