.net - CultureInfo.DisplayName 去萨米我

为什么 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

https://stackoverflow.com/questions/2958364/

相关文章:

maven-2 - 使用 JMeter + Maven 和 https 协议(protocol)

.net - 是否有将图像重新抗锯齿为不同背景颜色的技术?

macos - 在 Mac OS X 上对文件更改运行脚本

visual-studio - 如何创建支持多实例(多次安装)的安装工程?

iphone - 在应用程序声音中禁用

.htaccess - htaccess 中的变量,RewriteRule 问题

django - 有没有办法修改 Django FileField 使用的存储后端?

sql-server - SQL Server 压力测试工具?

android - 连接到另一台机器上的 Android 模拟器

php - 我应该如何在 MySQL 数据库中存储 ftp 登录凭据?