-1

i need to find a solution to get the native spelling of the countryname in every Culture.

For example:

Germany, ISOCODE: DE

On german Windows-Systems there are the following informations:

  • Englishname : Germany
  • Nativename : Deutschland
  • Displayname : Deutschland

Now i need to know how "Germany"(Englishname) or "Deutschland" (Displayname / Nativename) is written in Netherlands for example.

Output must be

"Duitsland"

When in France, output must be

"Allemagne"
  • Every "Output" must be done programmatically.

Is it possible to get the different Displaynames from every Country for a single Country given?

Any help would be appreciated.

Edit: I tried, to change the CultureInfo of the Current Thread to mimic that i am not in germany but in france. But that doesn't worked as aspected. Here's the code i used:

            try
            {
                CultureInfo originalThreadCultureInfo = Thread.CurrentThread.CurrentUICulture;
                foreach (CultureInfo CI in CultureInfo.GetCultures(CultureTypes.AllCultures))
                {
                    try
                    {
                        if (CI.IsNeutralCulture || !string.IsNullOrEmpty(CI.Parent.Name))
                        {
                            Thread.CurrentThread.CurrentUICulture = CI;
                            Thread.CurrentThread.CurrentCulture = CI;
                            RegionInfo R = new RegionInfo(this.CultureID);
                            string EnglishName = R.EnglishName;
                            string NativeName = R.NativeName;
                            string DisplayName = R.DisplayName;
                        }
                    }
                    catch (Exception ex) { }

                }
                Thread.CurrentThread.CurrentCulture = originalThreadCultureInfo;
                Thread.CurrentThread.CurrentUICulture = originalThreadCultureInfo;
            }
            catch (Exception ex) { }
  • So... what did you try? Did you look at the properties that the [CultureInfo class](https://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo%28v=vs.110%29.aspx) has? – Camilo Terevinto Jul 06 '18 at 14:32
  • i tried, to change the CurrentThread Culture to "mimic" that i'm not in Germany but in France and then tried to get the RegionInfo from "DE" but that doesn't work – Daniel Alexander Karr Jul 06 '18 at 14:44
  • Try tooking at the GeographicRegion class, it might be of use to you: https://learn.microsoft.com/en-us/uwp/api/windows.globalization.geographicregion – Andy P Jul 06 '18 at 15:03
  • Thanks, is there any "non UWP"-Class? – Daniel Alexander Karr Jul 06 '18 at 15:43

2 Answers2

1

This is not a built-in functionality in the .NET Framework yet. You might use language translation APIs.

Tany3450
  • 338
  • 2
  • 11
  • After much contemplation, I agree. 'What do the people of France call the country known as The Netherlands?' is not in the framework. If only EnglishName was not available, the question would never have come up :P – Davesoft Jul 06 '18 at 15:00
  • So "yet" means i might come but will only be UWP/.NET Core. I will do a "dirty workaround" using "restcountries.eu" after i know the "ISOCode" of a country to get translations and alternative spellings, save them into a database and look it up if i don't get the ISOCode by the given spelling. – Daniel Alexander Karr Jul 06 '18 at 15:45
0

Well you can use a NuGet package - TheMulti0.EasyTranslate.

 ITranslator translator = new GoogleTranslateClassicTranslator();     
 TranslateWord result = translator.Translate(new TranslateWord("Germany"), TranslateLanguages.Dutch);
 Console.WriteLine(result.Word);

Output

Duitsland
Prany
  • 2,078
  • 2
  • 13
  • 31