Country codes in the i18n localization library for Rails

The powerful Ruby on Rails Localization library is truly awesome. We have discussed in other ocassions about it and also about ways of localizing the javascripts .

Today we have another item to discuss. It is about geographic/country specific versions of a language that you would like to offer to your users.

In this question, a user is asking how to manage codes such as en-US, en-GB, es-ES, i.e. language codes that include also a geographic code of the language variation that is used in a region or country: http://stackoverflow.com/questions/9859391/whats-the-proper-way-to-handle-geographic-locales-in-ruby-on-rails.

Set the locale you want:

I18n.locale = ‘en_US’

And use fallbacks to sort out the specific differences you need to cover

config.i18n.default_locale = ‘en’
config.i18n.fallbacks = {
‘en_US’ => ‘en’,
‘en_GB’ => ‘en’,
‘de_DE’ => ‘de’,
‘de’ => ‘en’
}

The issue may be if you are using urls with the locale in order to manage the different versions. Because in a url you should not use underscores (even if Wikipedia does and quite successfully!!), see why you should not in this article: http://blog.woorank.com/2013/04/underscores-in-urls-why-are-they-not-recommended/

So the urls would not be as clean. Maybe a solution is to use /en/ for all english content urls and underneath keep the geographic specific info en_EN or en_US.

Any suggestion? thanks for participating

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s