简体   繁体   中英

How to implement localization using ASP.NET Web API

I am currently developing a Web API using ASP.NET. The Web API will send a text messages to the customers around the world. 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. 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.

The UI layer should have localization (resx) files which includes different messages to be shown to the user.

The API should return a special object which has only error code and other error properties but not error message.

The UI layer can then parse the reply to see if there is any error code in API response. If there is, then UI can have logic to convert error code to appropriate resx string based on current culture of the UI application. This resx string then should be displayed to the user.

I hope this helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM