- Prerequisites
You must use i18n-tasks and make sure i18n-tasks health
is OK.
I recommend that running i18n-tasks health
along with your tests in CI.
-
Download i18n-tasks_js.rb as
lib/i18n_tasks/js.rb
in your project. -
Insert the line below into the top of
config/i18n-tasks.yml
<% require './lib/i18n_tasks/js' %>
- You will see the
js-keys
command is installed.
$ i18n-tasks -h
...
js-keys export i18n keys that used in js
- Export js-keys.json
$ i18n-tasks js-keys > tmp/js-keys.json
- Include
js-keys.json
as aonly
field like this.
translations:
- file: 'public/javascripts/path-to-your-messages-file.js'
only: <%= File.read('tmp/js-keys.json') %>
Your i18n:js:export process may look like this:
i18n-tasks js-keys > tmp/js-keys.json && rake i18n:js:export