问题
The following things/behaviors are expected in multi lingual application.
- To pick up the correct resources for the logged in user’s language
- The string sort should happen according to user language (For example: in case of Swedish users, the Swedish alphabets should come after z in Order).
- The date time format validation should happen according to the user’s language. (For example: fr-FR users can enter dd/mm/yyyy and en-US users can enter mm/dd/yyyy)
- The decimal validation again should happen according to user’s language (For example: 12,5 is valid in French whereas 12.5 is invalid)
Now the question is what is the best way to handle this.
Approach 1:
- Set the page culture and page UICulture – so that the App_GlobalResources are picked up and decimal values in grid are correctly formatted.
- Write custom methods to fire validation for the following
- Datetime
- Decimal
- Write custom method to handle string sorting.
Approach 2:
- Set the current thread’s culture and let this handle the following { Does each user of the web app have their culture correctly set in this case?}
Approach 3:
Initialize the globalization attribute in web.config and letting the application pick culture based on the user’s browser culture
<globalization uiculture="auto" culture="auto" enableClientBasedCulture =”true”/>
Please let me know if there are better alternatives and how should we approach solving such problems or the pros and cons of the above approaches.
回答1:
Overload the InitializeCulture() page event. Use a session var based on the autheticated user, which stores the currentliy selected culture and reset both Thread.Culture and UICulture in the event handler.
As far as I know, these conversion issues or ToString() format issues should no exist. The current thread culture will handle all for you.
Some resources:
Walkthrough: Using Resources for Localization with ASP.NET
How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization
来源:https://stackoverflow.com/questions/5754685/best-way-to-implement-a-multilingual-in-asp-net-application