How can I identify unused i18n keys?

后端 未结 5 1623
萌比男神i
萌比男神i 2021-02-04 03:42

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

5条回答
  •  天涯浪人
    2021-02-04 03:58

    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.

提交回复
热议问题