0

The problem

I've got the following information:

  • Language name
  • Country

An example would be: English, United States

This information needs to be converted into an ISO 639-2 three-letter code. It might be good to know that I'm using dotnet 6 with C# 10.

What I looked at so far

So far, I tried using the CultureInfo. Sadly, CultureInfo does not take a language and a country. I'm aware of the RegionInfo class, but from my understanding, it does not contain a mapping for all countries and it requires as an input something like "en-US" which I do not have.

ShadowDragon
  • 2,238
  • 5
  • 20
  • 32
  • you'll likely have to store a map of that – Daniel A. White Oct 27 '22 at 17:38
  • Language and Country are 2 different things. Even if you wanted to loosely say CultureInfo is similar to Language, and RegionInfo is similar to Country, you would need to map them together. Eastern Canada may prefer French, whereas Western Canada may prefer English (some UK English over US English). – Rick Davin Oct 27 '22 at 18:52
  • 1
    Besides `en-CA` English Canada and `fr-CA` French Canada, there are examples of Spanish versus Spain. A different version of Spanish is spoken in Span than in Mexico. Even within Spain, their are regional differences. Barcelona speaks as much Catalan `ca-ES` than Spanish `es-ES`. – Rick Davin Oct 27 '22 at 20:47
  • As a solution you can use CultureInfo.GetCultures() and then compare its properties with your inputs. Although if you want the best solution I think you should search for implementation of ISO 639 and ISO 3166 in .Net which has full language and countries name and its abbreviation in two or three letter. – Mehdi Mowlavi Feb 12 '23 at 11:06

0 Answers0