Better Rails 4 support

The past few weeks, we’ve been hard at work to integrate with Rails 4 as seamlessly as possible. There are 3 major points we’ve been focusing on: the Rails 4 library, the localeapp gem bug fixes and how we display missing translation. Let’s develop them.

Rails 4 library

We’re providing libraries for a few largely used frameworks and gems (like Rails, Devise, Kaminari, …). Those libraries can be added to your project from the “Libraries” menu, by selecting the library you want to embed with your project and then clicking on the “Add to project” big green button.

Those libraries copy a bunch of translation keys to you project in the languages it supports. They are then part of your project without any further effort and they do not count as keys for your plan limit 🙂

Anyway, Rails 4 is not very different (I18n-wise) from Rails 3, and we know many of you were using the Rails 3 library for your Rails 4 projects, specially as it is known to not break anything (or so little). But we thought Rails 4 now deserves its own library, so here you go:


Also, as Rails 4 is now the standard we all love to use, we thought it would be handy to be able to embed this library right when you create a new project. You simply have to select “Rails 4” from the “Include librares?” dropdown menu on the “new project” page. It looks like this:


Bonus: It’s a public project on Locale, so feel free to contribute!

Gem fixes

Better say some things straight: the implementation of the translate() helper in ActionView has been quite a mess since the early Rails 4 ages. And it’s fundamental to our gem as we’re pretty much hooking it (using the I18n ExceptionHandler class) to pull and push translations from/to our servers (via our API).

To make things simple to understand here the chronological facts:

  1. a change of behaviour was introduced in Rails 4.0.2 (and backported to 3.2.16, that’s just for fun!)
  2. a bug on this new behaviour has been introduced in 4.0.10.rc1
  3. a patch for this bug has been introduced but only in 4.1.10.rc1 for the 4.1.x branch and in 4.2.1.rc1 for the 4.2.x branch (ho! and it hasn’t been backported to the 4.0.x nor 3.2.x branches)

Anyway… the behaviour change needs a monkeypatch, and the bug another one (that actually only backports the bugfix). And we now detect Rails version acurately to determine which patch is needed to be applied.

If you’re curious, here’s the Rails version logic and it’s a nice mess:

rails-version-checkTL;DR: update your gem to 0.9.2 for a fully patched ActionView translate() helper 😉

And remember it’s always better to use the translate() (aliased as t()) helper in your views than I18n synonym method, i.e always prefer t(‘some.translation’) rather than I18n.t(‘some.translation’).

Missing translation display

We’re now sticking with Rails new behaviour of displaying missing translations. Rather than displaying the old ugly “translation missing: en.some_missing_key”, Rails is now displaying “Some Missing Translation” (which is the key titleized) wrapped in a span with the “translation_missing” class and “translation missing: en.some_missing_translation” as title attribute.

It’s better looking in a view and you can still quickly locate the missing translation thanks to the title attribute when stoping your cursor on the span.

We’re now doing this too, And we even added a “localeapp” class to the span.

missing-translationAll you need to do to benefit from this is to update the gem to 0.9.2.

This entry was posted in LocaleApp. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *