i18n-tasks 0.7.3 → 0.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.md +5 -0
- data/README.md +58 -34
- data/lib/i18n/tasks/command/commands/missing.rb +1 -1
- data/lib/i18n/tasks/slop_command.rb +3 -2
- data/lib/i18n/tasks/stats.rb +1 -1
- data/lib/i18n/tasks/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0d5a6d44abbe13489dbf413f1fe2934f96ac3ec
|
4
|
+
data.tar.gz: b73c633dbb50493e77f248a4d019473d38920c6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33f1b9a719ad5a1127be44b0513aa9e0f2cd46598c2d855c46be9fbb9e488164c4eacddbd0d7ef0da28e4db7ffd922162770d8dbe883acdb45cf5d8d44dfb28b
|
7
|
+
data.tar.gz: 625b026add3aa686380a485df1f1db04ab450092eac690d793eb0293f237752c823702164ec13e662a3d7e4d5717a0dd840bfebe41d65f796f97abacd58bef12
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -25,7 +25,7 @@ i18n-tasks can be used with any project using [i18n][i18n-gem] (default in Rails
|
|
25
25
|
Add to Gemfile:
|
26
26
|
|
27
27
|
```ruby
|
28
|
-
gem 'i18n-tasks', '~> 0.7.
|
28
|
+
gem 'i18n-tasks', '~> 0.7.4'
|
29
29
|
```
|
30
30
|
|
31
31
|
Copy default [configuration file](#configuration) (optional):
|
@@ -46,7 +46,7 @@ Run `i18n-tasks` to get the list of all the tasks with short descriptions.
|
|
46
46
|
|
47
47
|
### Check health
|
48
48
|
|
49
|
-
`i18n-tasks health`
|
49
|
+
`i18n-tasks health` checks if any keys are missing or not used:
|
50
50
|
|
51
51
|
```console
|
52
52
|
$ i18n-tasks health
|
@@ -60,26 +60,23 @@ Add missing keys with placeholders (base value or humanized key):
|
|
60
60
|
$ i18n-tasks add-missing
|
61
61
|
```
|
62
62
|
|
63
|
-
|
63
|
+
This and other tasks accept arguments:
|
64
64
|
|
65
65
|
```console
|
66
66
|
$ i18n-tasks add-missing -v 'TRME %{value}' fr
|
67
|
-
$ i18n-tasks add-missing --help
|
68
|
-
Usage: i18n-tasks add_missing [options] [locale ...]
|
69
|
-
-l, --locales Comma-separated list of locale(s) to process. Default: all. Special: base.
|
70
|
-
-f, --format Output format: terminal-table, yaml, json, keys, inspect. Default: terminal-table.
|
71
|
-
-v, --value Value. Interpolates: %{value}, %{human_key}, %{value_or_human_key}. Default: %{value_or_human_key}
|
72
|
-
-h, --help Display this help message.
|
73
67
|
```
|
74
68
|
|
75
|
-
`
|
69
|
+
Pass `--help` for more information:
|
76
70
|
|
77
71
|
```console
|
78
|
-
$ i18n-tasks missing
|
72
|
+
$ i18n-tasks add-missing --help
|
73
|
+
Usage: i18n-tasks add-missing [options] [locale ...]
|
74
|
+
-l, --locales Comma-separated list of locale(s) to process. Default: all. Special: base.
|
75
|
+
-f, --format Output format: terminal-table, yaml, json, keys, inspect. Default: terminal-table.
|
76
|
+
-v, --value Value. Interpolates: %{value}, %{human_key}, %{value_or_human_key}. Default: %{value_or_human_key}.
|
77
|
+
-h, --help Display this help message.
|
79
78
|
```
|
80
79
|
|
81
|
-
See command help for more information.
|
82
|
-
|
83
80
|
### Google Translate missing keys
|
84
81
|
|
85
82
|
Translate missing values with Google Translate ([more below on the API key](#translation-config)).
|
@@ -109,15 +106,9 @@ $ i18n-tasks unused
|
|
109
106
|
$ i18n-tasks remove-unused
|
110
107
|
```
|
111
108
|
|
112
|
-
These tasks will infer dynamic
|
109
|
+
These tasks will infer [dynamic keys](#dynamic-keys) such as `t("category.\#{category.name}")` by default.
|
113
110
|
Pass `-s` or `--strict` to disable this feature.
|
114
111
|
|
115
|
-
`i18n-tasks remove-unused` is roughly equivalent to:
|
116
|
-
|
117
|
-
```bash
|
118
|
-
$ i18n-tasks unused -fyaml | i18n-tasks data-remove
|
119
|
-
```
|
120
|
-
|
121
112
|
### Normalize data
|
122
113
|
|
123
114
|
Sort the keys:
|
@@ -132,26 +123,57 @@ Sort the keys, and move them to the respective files as defined by (`config.writ
|
|
132
123
|
$ i18n-tasks normalize -p
|
133
124
|
```
|
134
125
|
|
135
|
-
###
|
126
|
+
### Compose tasks
|
136
127
|
|
137
|
-
|
138
|
-
Scope argument is supported, but only when it is the first keyword argument ([improvements welcome](/lib/i18n/tasks/scanners/pattern_with_scope_scanner.rb)):
|
128
|
+
`i18n-tasks` also provides composable tasks for reading, writing and manipulating locale data.
|
139
129
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
130
|
+
For example, `add-missing` implemented with `missing`, `tree-set-value` and `data-merge`:
|
131
|
+
|
132
|
+
```console
|
133
|
+
$ i18n-tasks missing -fyaml fr | i18n-tasks tree-set-value 'TRME %{value}' | i18n-tasks data-merge
|
134
|
+
```
|
135
|
+
|
136
|
+
Another example, `remove-unused` implemented with `unused` and `data-remove`:
|
137
|
+
|
138
|
+
```bash
|
139
|
+
$ i18n-tasks unused -fyaml | i18n-tasks data-remove
|
145
140
|
```
|
146
141
|
|
147
|
-
|
142
|
+
See the full list of tasks with `i18n-tasks --help`.
|
143
|
+
|
144
|
+
### Features and limitations
|
145
|
+
|
146
|
+
#### Relative keys
|
147
|
+
|
148
|
+
`i18n-tasks` offers partial support for relative keys, such as `t '.title'`.
|
149
|
+
|
150
|
+
✔ Keys relative to the file path they are used in (see [relative roots configuration](#usage-search)) are supported.
|
151
|
+
|
152
|
+
✘ Keys relative to `controller.action_name` in Rails controllers are not supported.
|
153
|
+
|
154
|
+
#### Plural keys
|
155
|
+
|
156
|
+
✔ Plural keys, such as `key.{one,many,other,...}` are fully supported.
|
157
|
+
|
158
|
+
#### `t()` keyword arguments
|
159
|
+
|
160
|
+
✔ `scope` keyword argument is supported, but only when it is the first argument.
|
161
|
+
|
162
|
+
✘ `default` and other arguments are not supported.
|
163
|
+
|
164
|
+
Parsing keyword arguments correctly with Regexp is difficult. This can be improved with an s-expression parser.
|
165
|
+
|
166
|
+
#### Dynamic keys
|
167
|
+
|
168
|
+
By default, unused report will detect some dynamic keys and not report them, e.g.:
|
148
169
|
|
149
170
|
```ruby
|
150
|
-
t 'category.' + category.key # all 'category
|
151
|
-
t "category.#{category.key}.name" # all 'category
|
171
|
+
t 'category.' + category.key # all 'category.:' keys considered used (: denotes one key segment)
|
172
|
+
t "category.#{category.key}.name" # all 'category.:.name' keys considered used
|
152
173
|
```
|
153
174
|
|
154
|
-
|
175
|
+
This will not be on by default in future versions, in favour of encouraging explicit [i18n-tasks-use hints](#fine-tuning).
|
176
|
+
For now, you can disable dynamic key inference by passing `-s` or `--strict` to `unused` tasks.
|
155
177
|
|
156
178
|
## Configuration
|
157
179
|
|
@@ -164,6 +186,8 @@ Install the default config file with:
|
|
164
186
|
$ cp $(i18n-tasks gem-path)/templates/config/i18n-tasks.yml config/
|
165
187
|
```
|
166
188
|
|
189
|
+
Settings are compatible with Rails by default.
|
190
|
+
|
167
191
|
### Locales
|
168
192
|
|
169
193
|
By default, `base_locale` is set to `en` and `locales` are inferred from the paths to data files.
|
@@ -389,8 +413,8 @@ Add a custom task like the ones defined by the gem:
|
|
389
413
|
# my_commands.rb
|
390
414
|
class MyCommands
|
391
415
|
include ::I18n::Tasks::Command::Collection
|
392
|
-
cmd :
|
393
|
-
def
|
416
|
+
cmd :my_task, desc: 'my custom task'
|
417
|
+
def my_task(opts = {})
|
394
418
|
end
|
395
419
|
end
|
396
420
|
```
|
@@ -38,7 +38,7 @@ module I18n::Tasks
|
|
38
38
|
args: '[locale ...]',
|
39
39
|
desc: proc { I18n.t('i18n_tasks.cmd.desc.add_missing') },
|
40
40
|
opt: cmd_opts(:locales, :out_format) <<
|
41
|
-
cmd_opt(:value).merge(desc: "#{cmd_opt(:value)[:desc]}. #{I18n.t('i18n_tasks.cmd.args.default_text', value: DEFAULT_ADD_MISSING_VALUE)}")
|
41
|
+
cmd_opt(:value).merge(desc: proc { "#{cmd_opt(:value)[:desc].call}. #{I18n.t('i18n_tasks.cmd.args.default_text', value: DEFAULT_ADD_MISSING_VALUE)}" })
|
42
42
|
|
43
43
|
def add_missing(opt = {})
|
44
44
|
forest = i18n.missing_keys(opt).set_each_value!(opt[:value] || DEFAULT_ADD_MISSING_VALUE)
|
@@ -3,9 +3,10 @@ module I18n::Tasks::SlopCommand
|
|
3
3
|
|
4
4
|
def slop_command(name, attr, &block)
|
5
5
|
proc {
|
6
|
-
|
6
|
+
cmd_name = name.tr('_', '-')
|
7
|
+
command cmd_name do
|
7
8
|
args = attr[:args]
|
8
|
-
banner "Usage: i18n-tasks #{
|
9
|
+
banner "Usage: i18n-tasks #{cmd_name} [options] #{args}" if args.present?
|
9
10
|
desc = attr[:desc]
|
10
11
|
desc = desc.call if desc.respond_to?(:call)
|
11
12
|
description desc if desc
|
data/lib/i18n/tasks/stats.rb
CHANGED
@@ -12,7 +12,7 @@ module I18n::Tasks
|
|
12
12
|
locale_count: locale_count,
|
13
13
|
per_locale_avg: forest.inject(0) { |sum, f| sum + f.leaves.count } / locale_count,
|
14
14
|
key_segments_avg: '%.1f' % (forest.leaves.inject(0) { |sum, node| sum + node.walk_to_root.count - 1 } / key_count.to_f),
|
15
|
-
value_chars_avg: forest.leaves.inject(0) { |sum, node| sum + node.value.length } / key_count
|
15
|
+
value_chars_avg: forest.leaves.inject(0) { |sum, node| sum + node.value.to_s.length } / key_count
|
16
16
|
}
|
17
17
|
end
|
18
18
|
end
|
data/lib/i18n/tasks/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18n-tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- glebm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubis
|