Is there a way to get RegionInfo translated by a custom CultureInfo?
I tried the following but it does not work:
/* 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");
If the current culture is german I want to get "Deutschland" from RegionInfo("de"). If the current culture is englisch, it should be "Germany".
You can't use the RegionInfo for this - this class allows you only to get the Name in the language of your .NET installation (usually English), or a native name (in the language of the selected region).
You should use resource files for this (e.g. Res.resx: "de" "Germany"; Res.de.resx: "de" "Deutschland"; Res.pl.resx: "de" "Niemcy"...) then, in the code, the value of Res.de will be taken from the resx corresponding to your CurrentThread.CurrentUICulture.