LoginSignup
14
14

More than 5 years have passed since last update.

i18nの漏れをチェックする

Last updated at Posted at 2015-10-20

i18nの漏れをチェックする

glebm/i18n-tasks
で、i18nの漏れをチェックできるようだ。

% bundle exec i18n-tasks
Usage: i18n-tasks [command] [options]
    -v, --version            Print the version
    -h, --help               Show this message

Available commands:

    health                   is everything OK?
    missing                  show missing translations
    translate-missing        translate missing keys with Google Translate
    add-missing              add missing keys to locale data
    find                     show where keys are used in the code
    unused                   show unused translations
    remove-unused            remove unused keys
    eq-base                  show translations equal to base value
    normalize                normalize translation data: sort and move to the right files
    data                     show locale data
    data-merge               merge locale data with trees
    data-write               replace locale data with tree
    data-remove              remove keys present in tree from data
    tree-translate           Google Translate a tree to root locales
    tree-merge               merge trees
    tree-filter              filter tree by key pattern
    tree-rename-key          rename tree node
    tree-subtract            tree A minus the keys in tree B
    tree-set-value           set values of keys, optionally match a pattern
    tree-convert             convert tree between formats
    config                   display i18n-tasks configuration
    gem-path                 show path to the gem
    irb                      start REPL session within i18n-tasks context
    xlsx-report              save missing and unused translations to an Excel file

missing

色々機能はあるけど(Google翻訳を使うとかね)、
missingのみ使用することとした

missingでチェックしてくれるのはどんなこと?

missingパターン1
t()で呼ばれてるけどどこのYAMLににもないよ!

ターミナル出力

Locale Key Value in other locales or source
all hoge.foo.bar ファイル名.rb:行数


missingパターン2
ja.ymlにはあるけど他のYAMLにはないよ!

ターミナル出力

Locale Key Value in other locales or source
en hoge.foo.hello ja こんにちわ
zh-CN hoge.foo.hello ja こんにちわ

同じキーでも言語ごとに1行使って表示されるので、扱う言語が多いと縦に長い出力となりやや辛い。

missingのまとめ

t('キー')
 -> パターン1 どのYAMLにもないよ
 -> パターン2 ja.ymlにはあるけど他のにはないよ

ということで, t()で呼ばれてないものに関してはチェックできない

設定ファイル

glebm/i18n-tasksの設定ファイルはREADME.mdにある通り、自分でcpコマンドで持ってこよう。

とうことで設定ファイルが、config/i18n-tasks.ymlにできる。

設定ファイルの設定

自分が設定を加えた(もしくは変更した)項目は次の通り。
記載した以外のところはcpコマンドでもってきたままとした。

base_locale: ja
locales: [ja, en]

data:
  router: pattern_router

read from:
  read:
    - 'config/locales/%{locale}.yml'
    - 'config/locales/**/%{locale}.yml'
    - 'vendor/**/devise*/**/%{locale}.yml'
    - 'vendor/**/doorkeeper*/**/%{locale}.yml'

vendor配下の各種YAMLの場所も教えてあげないと
t()で呼ばれてるけどどこのYAMLににもないよ!
ということになってしまうので必須。

余談

missingだけ使うとはじめに書いたので、ここらは余談。

unused

missingt()メソッドにはあるけどYAMLにないよのチェックだった。
unusedはその逆。 YAMLにはあるけどt()メソッドにはないよ だ。

add-missing

親切にもmissingのチェックによって見つかったYAMLにないキーをYAMLに出力してくれる。ただし、自分で規則性をもってYAMLファイルを分割していた場合は、この機能はあってないようなものだろう。

14
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
14