代码之家  ›  专栏  ›  技术社区  ›  Martin

CultureInfo.DisplayName和我一样

  •  2
  • Martin  · 技术社区  · 16 年前

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

    MSDN说

    此属性表示.NET框架版本中的本地化名称。例如,如果安装了.NET Framework英文版本,则属性返回“English(United States)”作为en-US区域性名称。如果安装了.NET Framework西班牙语版本,则无论系统设置为显示何种语言,区域性名称都将以西班牙语显示,并且en-US的属性将返回“Ingles(Estados Unidos)”。

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

    我的web配置有:

    <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;
            }
        }
    
    1 回复  |  直到 16 年前
        1
  •  0
  •   Dirk Vollmar    16 年前

    我想你的窗口区域设置为 smj-sv 或者别的什么 similar . 然后,.NET框架将生成一个区域性,如

    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

    推荐文章