简体   繁体   中英

After set CultureInfo.DefaultThreadCurrentUICulture CultureInfo.DisplayName always returns english

After set CultureInfo.DefaultThreadCurrentUICulture CultureInfo.DisplayName always returns english.

I try

    CultureInfo cu = new CultureInfo("ja-JP");
    System.Threading.Thread.CurrentThread.CurrentCulture = cu;
    CultureInfo.DefaultThreadCurrentCulture = cu;
      // CultureInfo.DefaultThreadCurrentUICulture = cu;
    // SetDefaultCulture(cu);
    Dictionary<string, string> ifile = new Dictionary<string, string>();
    var regex = new System.Text.RegularExpressions.Regex(@"([\w+\s*\.*]+\))");
    foreach (var item in CultureInfo.GetCultures(CultureTypes.FrameworkCultures))
    {

      I18nCulture country = new I18nCulture();
      var match = regex.Match(item.DisplayName);
      string countryName = match.Value.Length == 0 ? item.EnglishName : match.Value.Substring(0, match.Value.Length - 1);
      if (item.Name != "")
      { 
        ifile.Add(item.Name, item.DisplayName);
      }
    }

    string fn = System.IO.Path.Combine(rootPath, "lib", "i18n", "culture", lng + ".json");
    Console.WriteLine("save : " + fn);
    saveObjectToJSON(ifile, fn);

When I run this code item.DisplayName is in german language, which is my current os system language. When I uncomment CultureInfo.DefaultThreadCurrentUICulture = cu; item.DisplayName is in english language. At this point I would expect ja-JP version of Display name.

How to get the culture display name in thread' s current culture?

您必须安装日语.NET Framework语言包

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM