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:

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:

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


Rails internationalization / localization

If you need to translate the rails strings, such as days of the week, months, time related strings and so on, you will see how simple it is.

Just download the corresponding file from here:

The detailed rails guide is here: