简体   繁体   English

在ASP.NET应用程序的web.config中参数化全球化标签

[英]Parameterize the globalization tag in web.config in an ASP.NET application

I am working on an application in which user has to enter the country he/she belongs to. 我正在开发一个用户必须输入他/她所属国家/地区的应用程序。

We want this to implement culture specific number formatting every time a user enter his/her country. 我们希望这在用户每次进入其国家/地区时实现特定于文化的数字格式。 Can we pass the country parameter to the globalization tag in web.config to make the application behave in accordance to the user's selected country? 我们能否将country参数传递到web.config中的全球化标签,以使应用程序根据用户选择的国家/地区运行?

<globalization uiCulture="CountryParam"  culture="CountryParam" />

Any help is deeply appreciated. 任何帮助深表感谢。

IN Asp.Net and/or MVC you just have to set Thread.CurrentThread.CurrentCulture and Thread.CurrentThread.CurrentUICulture to the culture of the user 在Asp.Net和/或MVC中,您只需要将Thread.CurrentThread.CurrentCultureThread.CurrentThread.CurrentUICulture设置为用户的区域性即可

If you do so, all formatting should be done based on this culture per default. 如果这样做,则默认情况下应根据此区域性来完成所有格式化。

Otherwise you would have to run string.Format with the specific culture provided by you in all places you do string formatting, using this overload ... 否则,您将不得不在所有进行字符串格式化的地方使用您提供的特定区域性运行string.Format,使用此重载 ...

As you can see in the documentation of string.Format, without defining a specific culture, it will use Thread.CurrentThread.CurrentCulture 如您在string.Format文档中所见,没有定义特定区域性,它将使用Thread.CurrentThread.CurrentCulture

Taken from here 从这里取

Generally, objects in the argument list are converted to their string representations by using the conventions of the current culture, which is returned by the CultureInfo.CurrentCulture property. 通常,参数列表中的对象通过使用Culture的约定(由CultureInfo.CurrentCulture属性返回)转换为其字符串表示形式。 You can control this behavior by calling the Format(IFormatProvider, String, Object[]) overload. 您可以通过调用Format(IFormatProvider,String,Object [])重载来控制此行为。 This overload's provider parameter is an IFormatProvider implementation that supplies custom and culture-specific formatting information that is used to moderate the formatting process. 此重载的provider参数是IFormatProvider实现,该实现提供用于调节格式化过程的自定义和特定于区域性的格式化信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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