-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Language codes to iso 3166 mapping #22
Comments
We don't have it in tr8n yet. But that would be a nice addition. There are few ways to determine the default language of the user. As you mentioned, one of them would be to use the ip, map it to the country and map it to the language. Unfortunately, country to language level mapping may not be enough, as there may be many different languages spoken in different regions (or even in the same region) of a country. A more reliable way would be to trust user browser default language. common_methods.rb which gets included into your application_controller has a method called: tr8n_user_preffered_locale this method uses tr8n_browser_accepted_locales to determine the first available language enabled in your site's tr8n, that is accepted (or specified) in the user's browser. The user language preferences are usually passed by the HTTP_ACCEPT_LANGUAGE header and it is usually a list of languages in user's priority - most desired first. So i would recommend to use that approach - If your user has not specifically chosen a language, use the tr8n_user_preffered_locale method to get the default locale for the user. Hope that helps. |
The problem with browser default language is the common usage of English browsers in countries around the world, in the Nordic countries for example most people use English versions of their browsers but expect sites like Facebook to be localized in their language. I think this is quite common in different parts of Asia as well. For our Your Priorities project its critical to try to give the best default language as possible and we believe the IP Country lookup is better than browser language settings. I've now implemented a basic version of this feature that uses iso 3166 and information from the CIA Factbook. This process results in around 200 correct country to language translations. This feature is included in this commit: Here is the data from the CIA and we are using the 3166 data from the iso website. |
One soft dependency on the IsoCountry class are the country flags, free icons for non-commercial but they suggest $40 donation for commercial use. But not really sure if this should be a part of tr8n... You can see this here: https://github.com/rbjarnason/open-active-democracy/tree/master/public/images/flags |
Is there a map file available anywhere that maps country codes to the language codes used in tr8n? To be used to default to the "right" language based on geoip return codes.
The text was updated successfully, but these errors were encountered: