2016-12-05 94 views
1

有没有办法让RegionInfo被自定义CultureInfo翻译?RegionInfo:DisplayName由CurrentUICulture翻译

我尝试以下,但它不工作:

/* Change culture of current thread to german*/ 
CultureInfo de = new CultureInfo("de"); 
Thread.CurrentThread.CurrentCulture = de; 
Thread.CurrentThread.CurrentUICulture = de; 
RegionInfo regionInfoDe = new RegionInfo("de"); 
regionInfoDe.DisplayName.Should().Be("Deutschland"); 

/* Change culture of current thread to englisch */ 
CultureInfo en = new CultureInfo("en"); 
Thread.CurrentThread.CurrentCulture = en; 
Thread.CurrentThread.CurrentUICulture = en; 
RegionInfo regionInfoEn = new RegionInfo("de"); 
regionInfoEn.DisplayName.Should().Be("Germany"); 

如果当前的文化是德国我想从RegionInfo“德国”(“德”)。如果现在的文化是英语,那应该是“德国”。

+0

如果'CultureInfo.CurrentCulture'是“de”和'DisplayName'时,你不能使用'NativeName'? – haim770

+0

我们讨论过这个解决方案,但是如果应用语言是英语,应该有“德国”而不是“德国”。 – Tobias

回答

1

您无法使用RegionInfo进行此操作 - 此类允许您仅使用.NET安装语言(通常是英语)或本地名称(使用选定区域的语言)获取名称。

您应该为此使用资源文件(例如Res.resx:“de”“Germany”; Res.de.resx:“de”“Deutschland”; Res.pl.resx:“de”“Niemcy”)。 ..),那么在代码中,Res.de的值将取自对应于CurrentThread.CurrentUICulture的resx。

+0

这就是我最终的结果。 – Tobias