I have a list of country codes and a list of language codes. How to match country code with language code?

When a user visits the site, I can get the country code. I want to use this to set the default language (which they can later change, if necessary, just a general assumption about what language they can speak, depending on what country they are in).

Is there a final mapping of country codes to language codes that exist somewhere? I could not find him. I know that not everyone in a particular country speaks the same language, but I just need a general mapping, the user can select their language manually later.

+7
internationalization localization nlp country-codes
source share
2 answers

A search for “displaying the country’s language” displays this table of Languages ​​by Country , which you could probably convert to language codes with a small amount of Work. (There are less than 200 countries.)

Warning: this is largely guaranteed to annoy many users in multilingual countries such as Switzerland or Canada. For such countries, it is customary to allow the user to choose their language on the main page of the user interface. For some examples, see Google Switzerland or Best Buy Canada . It also annoys expatriates and travelers.

Better yet, why don't you use the Accept-Language HTTP header to determine which language to use? The Accept-Language header is the right thing to consider when determining the user's language. It even gives you a list in order of preference, so if the user is most fluent in some language that you don’t support, but fluently enough in any other language that you support, you can retreat correctly. One problem with Accept-Language is that most users leave it by default. However, most browsers should set the platform language by default, so this is not so bad. (Some older browsers will default to English, which would be a disaster, because "en" effectively meant that Accept-Language was not installed.)

+8
source share

Although there may be good reasons to try to map countries (or really specific locations / areas within a country) to languages, it seems that for your purpose, using

Accept-Language HTTP Request Header,

if only one of the elements of the language selection heuristic (along with the country code) can be a simple and safe choice ...

This approach is sometimes erroneous, because the default language (s) associated with the installed installation of the web browser (when the basic user did not find the time to choose the installation package / setting for their preferred natural language). On the other hand, it also provides the best language guide for many expatriates (who install / configure the browser according to their preferred language), even if the geolocation / language association is completely wrong.

In general, this approach should surpass methods based solely on geolocation (and on a look-up table) in many countries, such as Switzerland, Luxembourg ... as well as many megacities speak in New York, Geneva or Miami ...

+4
source share

All Articles