Detecting untranslated keys in Rails
In our last project we are using multiple techniques to avoid deploying with untranslated keys. Quite often we put off the translations to just before committing since it can get really cumbersome and break your flow.
One approach is to start those strings with i19 in order to search the project folder for that key (‘i18’ proved quickly to be a bad idea), but this way you don’t find strings that you forgot to translate to all the languages and those with a wrong scope/name.
To make sure that you’ve got a translation for every given language, the gem i18n-spec it’s pretty handy, it checks that your locale files define the same set of keys.
For example, if I wanted to check that my locale files preferences.es.yml, frontpage.es.yml and preferences.en.yml, frontpage.en.yml are consistent between them, I could add this test:
You could tell rails to raise an exception whenever a missing translation occurs (see http://guides.rubyonrails.org/i18n.html#using-different-exception-handlers), this can be good for testing but we don’t use it in production (where we rather avoid showing a 500 for a missing key), not even in development since it could be really annoying (especially considering that the change in the locale files take sometime to ‘reload’, and sometimes you have to switch to another language in order to force it)
In development we take advantage of our dev bar (a fixed toolbar with shortcuts and useful info for development) to help the missing translations to stand out. We show a warning label, add an outline class to the html element and log the name of the missing key to the console.
in your view
in your styles
In order to detect missing translation coming from ajax requests you can add these lines (it only works with modern browsers, which trigger Dom insertion events)
The last thing that we have is an script in production which silently sends an error to Rollbar if it detects a missing key: