简体   繁体   English

如何使用ASP.NET Web API实现本地化

[英]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.

相关问题 如何在 Asp.Net 中使用 Web Api 在 Entity Framework 6 中实现事务? - How to implement transaction in Entity Framework 6 with Web Api in Asp.Net? 如何在ASP.NET Core Web API中实现通过id获取? - How to implement get by id in ASP.NET Core Web API? ASP.NET中如何实现搜索过滤 Core Web API - How to implement search filter in ASP.NET Core Web API 如何将幂等密钥实现为 asp.net web api? - How to implement Idempotent key into an asp.net web api? 如何在ASP.NET Web API中实现嵌套模型? - How to implement nested Models in ASP.NET Web API? 如何在ASP.NET Web API Core应用程序上使用QUARTZ实现调度程序? - How to implement a scheduler using QUARTZ on an ASP.NET Web API Core application? 如何使用AddMvcCore()实现“纯”ASP.NET Core Web API - How to implement a “pure” ASP.NET Core Web API by using AddMvcCore() 如何使用存储库架构在 ASP.NET MVC 应用程序中实现获取 Web API 数据? - How can I implement getting Web API data in an ASP.NET MVC app using the repository architecture? ASP.NET Core Web API - 如何使用 Fluent Validation 实现可选验证 - ASP.NET Core Web API - How to implement optional validation using Fluent Validation 如何在单独的 DTO 程序集中使用带有数据注释的本地化 (Asp.net Core Web Api) - How to use localization with data annotation in a separate DTO Assembly (Asp.net Core Web Api)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM