【发布时间】:2017-03-24 21:05:21
【问题描述】:
设置后CultureInfo.DefaultThreadCurrentUICulture CultureInfo.DisplayName 总是返回英文。
我试试
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);
当我运行此代码时,item.DisplayName 是德语,这是我当前的操作系统系统语言。当我取消注释 CultureInfo.DefaultThreadCurrentUICulture = cu; item.DisplayName 是英文。在这一点上,我希望 ja-JP 版本的显示名称。
如何获取线程当前文化中的文化显示名称?
【问题讨论】:
标签: c# .net internationalization