在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):glebm/i18n-tasks开源软件地址(OpenSource Url):https://github.com/glebm/i18n-tasks开源编程语言(OpenSource Language):Ruby 100.0%开源软件介绍(OpenSource Introduction):i18n-tasksi18n-tasks helps you find and manage missing and unused translations. This gem analyses code statically for key usages, such as
Thus addressing the two main problems of i18n gem design:
Installationi18n-tasks can be used with any project using the ruby i18n gem (default in Rails). Add i18n-tasks to the Gemfile: gem 'i18n-tasks', '~> 1.0.11' Copy the default configuration file: $ cp $(i18n-tasks gem-path)/templates/config/i18n-tasks.yml config/ Copy rspec test to test for missing and unused translations as part of the suite (optional): $ cp $(i18n-tasks gem-path)/templates/rspec/i18n_spec.rb spec/ Or for minitest: $ cp $(i18n-tasks gem-path)/templates/minitest/i18n_test.rb test/ UsageRun Check health
$ i18n-tasks health Add missing keysAdd missing keys with placeholders (base value or humanized key): $ i18n-tasks add-missing This and other tasks accept arguments: $ i18n-tasks add-missing -v 'TRME %{value}' fr Pass $ i18n-tasks add-missing --help
Usage: i18n-tasks add-missing [options] [locale ...]
-l, --locales Comma-separated list of locale(s) to process. Default: all. Special: base.
-f, --format Output format: terminal-table, yaml, json, keys, inspect. Default: terminal-table.
-v, --value Value. Interpolates: %{value}, %{human_key}, %{value_or_human_key}, %{key}. Default: %{value_or_human_key}.
-h, --help Display this help message. Google Translate missing keysTranslate missing values with Google Translate (more below on the API key). $ i18n-tasks translate-missing
# accepts from and locales options:
$ i18n-tasks translate-missing --from=base es fr DeepL Pro Translate missing keysTranslate missing values with DeepL Pro Translate (more below on the API key). $ i18n-tasks translate-missing --backend=deepl
# accepts from and locales options:
$ i18n-tasks translate-missing --backend=deepl --from=en fr nl Yandex Translate missing keysTranslate missing values with Yandex Translate (more below on the API key). $ i18n-tasks translate-missing --backend=yandex
# accepts from and locales options:
$ i18n-tasks translate-missing --from=en es fr Find usagesSee where the keys are used with $ i18n-tasks find common.help
$ i18n-tasks find 'auth.*'
$ i18n-tasks find '{number,currency}.format.*' Remove unused keys$ i18n-tasks unused
$ i18n-tasks remove-unused These tasks can infer dynamic keys such as If you want to keep the ordering from the original language file when using remove-unused, pass
Normalize dataSort the keys: $ i18n-tasks normalize Sort the keys, and move them to the respective files as defined by $ i18n-tasks normalize -p Move / rename / merge keys
All nodes (leafs or subtrees) matching Rename a node (leaf or subtree): $ i18n-tasks mv user account Move a node: $ i18n-tasks mv user_alerts user.alerts Move the children one level up: $ i18n-tasks mv 'alerts.{:}' '\1' Merge-move multiple nodes: $ i18n-tasks mv '{user,profile}' account Merge (non-leaf) nodes into parent: $ i18n-tasks mv '{pages}.{a,b}' '\1' Delete keysDelete the keys by using the $ i18n-tasks rm 'user.{old_profile,old_title}' another_key Compose tasks
$ i18n-tasks missing -f yaml fr | i18n-tasks tree-set-value 'TRME %{value}' | i18n-tasks data-merge
$ i18n-tasks unused -f yaml | i18n-tasks data-remove Remove all keys from $ i18n-tasks missing -t diff -f yaml en | i18n-tasks tree-mv en fr | i18n-tasks data-remove See the full list of tasks with Features and limitations
Relative keys
Plural keys
Reference keys
|
syntax | description |
---|---|
* |
matches everything |
: |
matches a single key |
{a, b.c} |
match any in set, can use : and * , match is captured |
Example of usage:
$ bundle exec i18n-tasks mv "{:}.contents.{*}_body" "\1.attributes.\2.body"
car.contents.name_body ⮕ car.attributes.name.body
car.contents.description_body ⮕ car.attributes.description.body
truck.contents.name_body ⮕ truck.attributes.name.body
truck.contents.description_body ⮕ truck.attributes.description.body
If you store data somewhere but in the filesystem, e.g. in the database or mongodb, you can implement a custom adapter. If you have implemented a custom adapter please share it on the wiki.
i18n-tasks uses an AST scanner for .rb
and .html.erb
files, and a regexp scanner for all other files.
New scanners can be added easily: please refer to this example.
See the search
section in the config file for all available configuration options.
NB: By default, only the app/
directory is searched.
Add hints to static analysis with magic comment hints (lines starting with (#|/) i18n-tasks-use
by default):
# i18n-tasks-use t('activerecord.models.user') # let i18n-tasks know the key is used
User.model_name.human
You can also explicitly ignore keys appearing in locale files via ignore*
settings.
If you have helper methods that generate translation keys, such as a page_title
method that returns t '.page_title'
,
or a Spree.t(key)
method that returns t "spree.#{key}"
, use the built-in PatternMapper
to map these.
For more complex cases, you can implement a custom scanner.
See the config file to find out more.
i18n-tasks translate-missing
requires a Google Translate API key, get it at Google API Console.
Where this key is depends on your Google API console:
In both cases, you may need to create the key if it doesn't exist.
Put the key in GOOGLE_TRANSLATE_API_KEY
environment variable or in the config file.
# config/i18n-tasks.yml
translation:
google_translate_api_key: <Google Translate API key>
i18n-tasks translate-missing
requires a DeepL Pro API key, get it at DeepL.
# config/i18n-tasks.yml
translation:
deepl_api_key: <DeepL Pro API key>
deepl_host: <optional>
deepl_version: <optional>
i18n-tasks translate-missing
requires a Yandex API key, get it at Yandex.
# config/i18n-tasks.yml
translation:
yandex_api_key: <Yandex API key>
i18n-tasks irb
starts an IRB session in i18n-tasks context. Type guide
for more information.
See i18n-tasks wiki: CSV import and export tasks.
Tasks that come with the gem are defined in lib/i18n/tasks/command/commands. Custom tasks can be added easily, see the examples on the wiki.
bundle install
bundle exec rspec
overcommit --install
SKIP=RuboCop git commit
OVERCOMMIT_DISABLE=1 git commit
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论