在 ASP.NET 应用程序中实现多语言的最佳方法
多语言应用程序中预计会发生以下事情/行为。
- 为登录用户的语言选取正确的资源
- 字符串排序应根据用户语言进行(例如:对于瑞典用户,瑞典字母应按顺序排列在 z 之后)。
- 日期时间格式验证应根据用户的语言进行。 (例如:fr-FR 用户可以输入 dd/mm/yyyy,en-US 用户可以输入 mm/dd/yyyy)
- 小数点验证应根据用户的语言再次进行(例如:12,5 在法语中有效,而12.5 无效)
现在的问题是处理这个问题的最佳方法是什么。
方法 1:
- 设置页面区域性和页面 UICulture – 以便选取 App_GlobalResources 并正确格式化网格中的小数值。
- 编写自定义方法来触发以下验证
- 日期时间
- 十进制
- 编写自定义方法来处理字符串排序。
方法 2:
- 设置当前线程的区域性并让它处理以下内容{在这种情况下,Web 应用程序的每个用户都正确设置了其区域性吗?}
方法 3:
初始化 web.config 中的全球化属性并让应用程序根据用户的浏览器文化选择文化
;
请告诉我是否有更好的替代方案以及我们应该如何解决此类问题或利弊上述方法中。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
重载InitializeCulture() 页面事件。使用基于经过身份验证的用户的会话变量,该变量存储当前选择的区域性并在事件处理程序中重置 Thread.Culture 和 UICulture。
据我所知,这些转换问题或 ToString() 格式问题应该不存在。当前的线程文化将为您处理所有问题。
一些资源:
演练:通过 ASP.NET 使用资源进行本地化< /a>
如何:设置 ASP 的区域性和 UI 区域性.NET 网页全球化
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