开发者

setting up a countries table for Rails i18n

开发者 https://www.devze.com 2023-04-06 04:02 出处:网络
In preparation to internationalize our Rails app, I\'m finding开发者_如何学Python we need to create a countries table and model that would contain (among other things) the default locale for each coun

In preparation to internationalize our Rails app, I'm finding开发者_如何学Python we need to create a countries table and model that would contain (among other things) the default locale for each country. I found a 4 year old resource http://snippets.dzone.com/posts/show/1727 that has most of what I want, but not locale. Does everybody have to piece this part together by hand or am I overlooking some easier way to map country to a default locale.

P.S. We already look up a users country using GeoIpCountry which works nicely, but that table only provides country name and 2-letter abbreviation. I also want to use country to assign the users default locale, currency, and 3-letter abbreviation (needed by a third party integration)


The best way to identify user's locale is to look up the HTTP request's Accept-Language setting.

e.g., mine says: Accept-Language: fr-BE

Which gives you my locale, my language (fr: french) and my country (BE: Belgium).

Also, remember that locale identification based on country is wrong in many countries, such as mine: Many websites identify my country (Belgium) correctly and assume a default locale: nl-BE because 60% of belgian people speak Dutch (nl). Hence these sites have it wrong for 40% of belgian visitors (including me).

Their site is a bad experience for me because it displays in a language which is not mine and the first thing I must do is look for their tiny language popup menu.

Had they simply looked up my Accept-Language, they would have shown me their site in my language right away.


have a look at: https://github.com/mm1/country-list

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号