如何在 RegionInfo.DisplayName 上强制 culture/region
How to force culture/region on RegionInfo.DisplayName
我将国家/地区显示为其他信息的一部分。
该国家作为国家代码从数据库中读出。
这样做是这样的:
Location location = new Location()
{
Company = reader.GetString("Company"),
Address1 = reader.GetString("Address"),
Address2 = reader.GetString("Address2", string.Empty),
ZipCity = reader.GetString("ZipCity"),
Country = new RegionInfo(reader.GetString("Country", string.Empty)).DisplayName,
CountryCode = new RegionInfo(reader.GetString("Country", string.Empty)).TwoLetterISORegionName,
Att = reader.GetString("Att", string.Empty),
Phone = reader.GetString("Phone", string.Empty)
};
我的问题是我真的很想强制使用丹麦语显示名称。
请注意,该国家/地区现在将始终是丹麦,因此无法使用本地名称。
非常感谢您
来自MSDN:
The DisplayName property displays the country/region name in the
language of the localized version of .NET Framework. For example, the
DisplayName property displays the country/region in English on the
English version of the .NET Framework, and in Spanish on the Spanish
version of the .NET Framework.
因此,如果您安装丹麦语版本的 .NET,它应该可以正常工作。
但是,最好不要依赖它,而是创建自己的 table 丹麦国家/地区名称。
因此,在检查了为 .NET Framework 安装语言包的可能性后,由于某种原因我们无法安装,我们找到了以下解决方案。
将此行添加到 system.web 节点下的 web.config。
<globalization enableClientBasedCulture="false" culture="da-DK" uiCulture="da"/>
如果您的计算机 运行 上安装了 OS 语言包,您的软件现在将被强制使用该语言。
您可以通过在实例化 RegionInfo 之前编写该行来解决该问题:
Thread.CurrentThread.CurrentUICulture = new CultureInfo("da-DK");
我将国家/地区显示为其他信息的一部分。 该国家作为国家代码从数据库中读出。
这样做是这样的:
Location location = new Location()
{
Company = reader.GetString("Company"),
Address1 = reader.GetString("Address"),
Address2 = reader.GetString("Address2", string.Empty),
ZipCity = reader.GetString("ZipCity"),
Country = new RegionInfo(reader.GetString("Country", string.Empty)).DisplayName,
CountryCode = new RegionInfo(reader.GetString("Country", string.Empty)).TwoLetterISORegionName,
Att = reader.GetString("Att", string.Empty),
Phone = reader.GetString("Phone", string.Empty)
};
我的问题是我真的很想强制使用丹麦语显示名称。 请注意,该国家/地区现在将始终是丹麦,因此无法使用本地名称。
非常感谢您
来自MSDN:
The DisplayName property displays the country/region name in the language of the localized version of .NET Framework. For example, the DisplayName property displays the country/region in English on the English version of the .NET Framework, and in Spanish on the Spanish version of the .NET Framework.
因此,如果您安装丹麦语版本的 .NET,它应该可以正常工作。
但是,最好不要依赖它,而是创建自己的 table 丹麦国家/地区名称。
因此,在检查了为 .NET Framework 安装语言包的可能性后,由于某种原因我们无法安装,我们找到了以下解决方案。
将此行添加到 system.web 节点下的 web.config。
<globalization enableClientBasedCulture="false" culture="da-DK" uiCulture="da"/>
如果您的计算机 运行 上安装了 OS 语言包,您的软件现在将被强制使用该语言。
您可以通过在实例化 RegionInfo 之前编写该行来解决该问题:
Thread.CurrentThread.CurrentUICulture = new CultureInfo("da-DK");