【问题标题】:CultureInfo.DisplayName going Sami on meCultureInfo.DisplayName 对我来说是萨米语
【发布时间】:2010-06-02 13:55:39
【问题描述】:

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

MSDN 说

此属性表示 .NET Framework 版本的本地化名称。例如,如果安装了 .NET Framework 英文版,则该属性将返回“English (United States)”作为 en-US 区域性名称。如果安装了 .NET Framework 西班牙语版本,则无论系统设置显示哪种语言,文化名称都以西班牙语显示,并且 en-US 的属性返回“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;
        }
    }

【问题讨论】:

    标签: .net cultureinfo


    【解决方案1】:

    我假设您的 Window 语言环境设置为 smj-svsimilar。然后,.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

    【讨论】:

    • 感谢您的建议。我照你说的做了。没什么新鲜的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    相关资源
    最近更新 更多