Search code examples
c#.netcultureinfoisoculture

CultureInfo and ISO 639-3


I'm searching a way to construct a CultureInfo object from a ISO 639-3 language code. I didn't find anything in the MSDN about that and trying to get it from the list of all cultures didn't work...

CultureInfo cInfo = CultureInfo.GetCultures(CultureTypes.AllCultures)
    .FirstOrDefault(r => String.Equals(r.ThreeLetterISOLanguageName, "CCH",
        StringComparison.CurrentCultureIgnoreCase));

will always return null (note that "CCH" is one language from the ISO-639-3 list).

Any idea is appreciated, thanks !


Solution

  • The MSDN documentation states that CultureInfo objects only have ISO 639-2 three-letter code and ISO 639-1 two-letter code. That means you are going to need a mapping of some kind in order to link your ISO 639-3 code to a specific CultureInfo instance.

    This Wikipedia page has the table with the mappings. Maybe you could cut-and-paste into an XML file and use it as an embedded resource in a class library in order to provide the mapping. Or even just define a static Dictionary<string,string> somewhere.

    Alternatively, I'm sure there will be a 3rd party library that can do this for you (though I don't know of any off the top of my head).

    edit:

    I hadn't realised ISO 639-3 codes only sometimes have a mapping to ISO 639-2 codes. The problem here is that the CultureInfo class isn't designed to handle the ISO 639-3 specification, so you may have to find a completely different 3rd party implementation of CultureInfo which will support this - or make it yourself.