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

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s