Language Codes by Country – Comprehensive List of Language Codes by Country

data

Does anyone know of a list of countries with their associated official language codes? I haven't found anything by Googling yet.

What I'm looking for is something like this:

Country name/code              Language code
[...]
Bulgaria (BG)                  bg
Belgium (BE)                   nl, fr
[...]    

Some further clarifications:

How is there not a correlation between a country and its official language(s)?

In my application this is relevant because I want to redirect someone who accesses it from the US to ${path}/us/en/, so I need to get the official language tag. I get the country code from a geolocation web service and I need the associated (official) language code.

For example, I have everything on my computer set to english, but I live in Romania. When I access it I don't want to get redirected to the UK version, ro/en does not exist, so I want ro/ro.

I wanted to see if there was an already aggregated list so that I wouldn't have to do it manually. If there isn't, I'll build one :).

Best Answer

The countryInfo file from http://geonames.org (http://download.geonames.org/export/dump/countryInfo.txt) has names, country codes, languages and lots of other info. It is a tab separated list so awk or any text editor will let you select just the columns you need.