gpt4 book ai didi

.net - CultureInfo.DisplayName 去萨米我

转载 作者:行者123 更新时间:2023-12-05 08:02:46 26 4
gpt4 key购买 nike

为什么 CultureInfo.DisplayName 在 Sami 中突然间?我用它来显示国家名称列表。也许这不是一个好主意,但它直到最近才奏效,而且我很确定它是瑞典语的(我猜它可能是英语的。)

MSDN 说

This property represents the localized name from the .NET Framework version. For example, if the .NET Framework English version is installed, the property returns "English (United States)" for the en-US culture name. If the .NET Framework Spanish version is installed, regardless of the language that the system is set to display, the culture name is displayed in Spanish and the property for en-US returns "Ingles (Estados Unidos)".

但我很确定我没有安装 Sami 版本的框架。

我的网络配置有:

<globalization
culture="sv-SE"
uiCulture="sv-SE"/>

添加:代码

        public static IEnumerable<KeyValuePair<string, string>> CountryList
{
get
{
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture("sv-SE");
Thread.CurrentThread.CurrentUICulture = new
CultureInfo("sv-SE");

var cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures);
/*Array.Sort(countries.Select(
x => Regex.Match(x.DisplayName, "\\(([\\w- ]+)\\)").ToString()).ToArray(),
countries);
*/

SortedDictionary<string, CultureInfo> d = new SortedDictionary<string, CultureInfo>();
foreach (CultureInfo cultureInfo in cultures)
{
string key = Regex.Match(cultureInfo.DisplayName, "\\(([\\w- ]+)\\)").ToString();
if (!d.ContainsKey(key))
d.Add(key, cultureInfo);
}

var countries = d
.Where(x => Regex.Match(x.Value.DisplayName, "\\([A-ZÅÄÖ]").Success)
.Select(
x => new KeyValuePair<string, string>(
Regex.Match(x.Value.Name, "-(\\w+)").Groups[1].ToString(),
Regex.Match(x.Value.DisplayName, "\\(([\\w- ]+)\\)").Groups[1].ToString()
));
return countries;
}
}

最佳答案

我假设您的窗口区域设置为 smj-sv 或其他 similar .然后 .NET Framework 将生成一种文化,如

Cultures Generated from Windows Locales

通常,您的 Web.config 中的值应该覆盖 Windows(用户的)区域设置,但也许这些值不再从您的 Web.config 中获取。您是否检查过文件未损坏且有效?

要查看您的 Web.config 是否有问题,我会尝试通过覆盖此处描述的 InitializeCulture 方法以编程方式设置语言:

How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization

关于.net - CultureInfo.DisplayName 去萨米我,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2958364/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com