Alex Rivera | Logout

How can I identify unused i18n keys?

Asked 2011-12-28T19:56:22.743
23

I'm working on an existing Rails app and am using a localization file, en.yml, to hold most of the app's text. At the moment, we aren't localizing into any other languages, so there's just the one file, but the fact that we're putting translate('some.key') into our views means that adding another language will be as simple as adding another file - say, sp.yml

The problem is, en.yml has grown to the point that I doubt all the keys are being used.

Apart from git grepping for translate calls using each key, is there a quick way to identify localization keys that aren't being explicitly called by the app?

Edit
Report

2 Answers

16

Take a look at this article about "Key issues internationalizing your app". The paragraph that interests you is: "Getting rid of unused translations".

Specifically, it recommends looking through your source code and also logging what translation keys get used in your production app, as follows:

module I18n
  module Registry
    protected
    def lookup(locale, key, scope = [], options = {})
      @log ||= Logger.new(File.join(Rails.root, 'log', 'i18n_registry.log'))
      @log.info key
      super
    end
  end
end

I18n::Backend::Simple.send :include, I18n::Registry

Hope that helps.

answered 2012-04-18T14:27:56.727
-2

You might want to try

$ ruby script/plugin install http://github.com/o2sources/unused_translations/tree/master
$ script/unused_translations config/locales/en.yml 

Source: http://www.railslodge.com/plugins/1547-unused-i18n-translations

answered 2012-02-23T15:28:57.357

Your Answer