如何识别未使用的i18n密钥? [英] How can I identify unused i18n keys?

查看:83
本文介绍了如何识别未使用的i18n密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用现有的Rails应用程序,并且正在使用本地化文件en.yml来保存应用程序的大部分文本.目前,我们尚未本地化为任何其他语言,因此只有一个文件,但是我们将translate('some.key')放入视图的事实意味着添加另一种语言就像添加另一种文件一样简单-说,sp.yml

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

问题在于,en.yml已经发展到我怀疑所有键都被使用的程度.

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

除了使用每个键的git grepping调用translate之外,还有一种快速的方法来识别未由应用程序明确调用的本地化键?

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?

推荐答案

看看有关.您感兴趣的段落是:"摆脱未使用的翻译".

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

希望有帮助.

这篇关于如何识别未使用的i18n密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆