README.md in i18n-tasks-0.2.19 vs README.md in i18n-tasks-0.2.20
- old
+ new
@@ -3,10 +3,25 @@
Tasks to manage translations in ruby applications using I18n.
![i18n-screenshot](https://raw.github.com/glebm/i18n-tasks/master/doc/img/i18n-tasks.gif "i18n-tasks output screenshot")
+## Installation
+
+Simply add to Gemfile:
+
+```ruby
+gem 'i18n-tasks', '~> 0.2.20'
+```
+
+If not using Rails, require the tasks in Rakefile:
+
+```ruby
+# Rakefile
+load 'tasks/i18n-tasks.rake'
+```
+
## Usage
Use `rake -T i18n` to get the list of tasks with descriptions. These are [the tasks](/lib/tasks/i18n-tasks.rake) available:
There are reports for missing and unused translations:
@@ -54,34 +69,18 @@
`i18n:unused` will detect pattern translations and not report them, e.g.:
```ruby
-t 'category.' + category.key # 'category.arts_and_crafts' considered used
+t 'category.' + category.key # category.* keys are all considered used
t "category.#{category.key}" # also works
```
Relative keys (`t '.title'`) and plural keys (key.one/many/other/etc) are fully supported.
-For more examples see [the tests](/spec/i18n_tasks_spec.rb).
+Translation data storage, key usage search, and other [settings](#configuration) are compatible with Rails by default.
-
-## Installation
-
-Simply add to Gemfile:
-
-```ruby
-gem 'i18n-tasks', '~> 0.2.10'
-```
-
-If not using Rails, require the tasks in Rakefile:
-
-```ruby
-# Rakefile
-load 'tasks/i18n-tasks.rake'
-```
-
## Configuration
Configuration is read from `config/i18n-tasks.yml` or `config/i18n-tasks.yml.erb`.
By default, `i18n-tasks` will work with `I18n.default_locale` and `I18n.available_locales`, but you can override this:
@@ -90,28 +89,35 @@
# config/i18n-tasks.yml
base_locale: en
locales: [es, fr]
```
+On Rails, if locales are set in the config file, you can make i18n tasks a lot faster by adding this to `Rakefile`:
+
+```ruby
+# disable loading :environment for i18n-tasks
+Rake::Task['i18n:setup'].clear_prerequisites
+```
+
### Storage
```yaml
# i18n data storage
data:
- # The default YAML adapter supports reading from and writing to YAML files
- adapter: yaml
+ # The default file adapter supports YAML and JSON files. You can provide a custom class name here.
+ adapter: file_system
# a list of file globs to read from per-locale
read:
- # this one is default:
+ # default:
- 'config/locales/%{locale}.yml'
- # add this one to also read from namespaced files, e.g. simple_form.en.yml:
+ # to also read from namespaced files, e.g. simple_form.en.yml:
- 'config/locales/*.%{locale}.yml'
# a list of {key pattern => file} routes, matched top to bottom
write:
- # this would save all devise keys in it's own file (per locale):
+ # save all devise keys in it's own file (per locale):
- ['devise.*', 'config/locales/devise.%{locale}.yml']
- # this is the default catch-all:
+ # default catch-all:
- 'config/locales/%{locale}.yml' # path is short for ['*', path]
```
Key matching syntax:
@@ -125,17 +131,28 @@
```yaml
data:
write:
# store sorcery and simple_form keys in the respective files:
- - ['{sorcery,simple_form}.*', 'config/locales/\\1.%{locale}.yml']
- # write every namespace to its own file:
+ - ['{sorcery,simple_form}.*', 'config/locales/\1.%{locale}.yml']
+ # write every key namespace to its own file:
- ['{:}.*', 'config/locales/\1.%{locale}.yml']
```
### Usage search
+Inspect all the usages with:
+
+```bash
+rake i18n:usages
+```
+
+![i18n-screenshot](https://raw.github.com/glebm/i18n-tasks/master/doc/img/i18n-usages.png "rake i18n:usages output screenshot")
+
+
+Configure usage search in `config/i18n-tasks.yml`:
+
```yaml
# i18n usage search in source
search:
# search these directories (relative to your Rails.root directory, default: 'app/')
paths:
@@ -162,12 +179,12 @@
- app/views
# add a custom one:
- app/views-mobile
```
-It is also possible to use a key scanner by setting `search.scanner`.
-See [the default scanner](/lib/i18n/tasks/scanners/pattern_scanner.rb) for reference.
+It is also possible to use a custom key usage scanner by setting `search.scanner` to a class name.
+See [the default pattern scanner](/lib/i18n/tasks/scanners/pattern_scanner.rb) for reference.
### Fine-tuning
Tasks may incorrectly report framework i18n keys as missing, also some patterns may not be detected.
@@ -213,28 +230,27 @@
You might want to test for missing and unused translations as part of your test suite.
This is how you can do it with rspec:
```ruby
-# spec_helper.rb
+# spec/i18n_keys_spec.rb:
+require 'spec_helper'
+
require 'i18n/tasks'
-require 'i18n/tasks/base_task'
-# spec/i18n_keys_spec.rb
-require 'spec_helper'
-describe 'translation keys' do
+describe 'Translation keys' do
let(:i18n) { I18n::Tasks::BaseTask.new }
it 'are all present' do
- expect(i18n.untranslated_keys).to have(0).keys
+ expect(i18n.missing_keys).to have(0).keys
end
it 'are all used' do
expect(i18n.unused_keys).to have(0).keys
end
-
end
+
```
## XLSX
Export missing and unused data to XLSX:
@@ -251,9 +267,5 @@
---
This was originally developed for [Zuigo](http://zuigo.com/), a platform to organize and discover events.
[MIT license](/LICENSE.txt)
-
-
-[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/glebm/i18n-tasks/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
-