i18n-tasks 0.7.2 → 0.7.3
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 +9 -1
- data/config/i18n-tasks.yml +1 -1
- data/config/locales/en.yml +2 -1
- data/config/locales/ru.yml +2 -1
- data/lib/i18n/tasks/command/commands/missing.rb +3 -8
- data/lib/i18n/tasks/command/commands/tree.rb +12 -0
- data/lib/i18n/tasks/command/options/locales.rb +7 -2
- data/lib/i18n/tasks/google_translation.rb +25 -16
- data/lib/i18n/tasks/version.rb +1 -1
- data/spec/google_translate_spec.rb +11 -9
- data/templates/config/i18n-tasks.yml +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ace77283059f5ec38fb4cf6eb85d51fa72ee175f
|
4
|
+
data.tar.gz: 2a9dc502ce2169a6c0e31a100346ff8ce8602c95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fbb5e12fdd92b788e8f88fd755195bc7d6040e22221b7d7087d16e5d011bfae89109a6fe425fbcdab4d264955ddcd5c2877f17e66ebd663396f48aa3faeabead
|
7
|
+
data.tar.gz: bcf27a97b3fee099d9c1826f69e892060518e0fcc4d84ae89f64a4f638300e9faa4b6504396ddfe558153a1f689ecb21f6b683c581789354772dc38da275c662
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 0.7.3
|
2
|
+
|
3
|
+
* New task `translate-tree`
|
4
|
+
* Bugs fixed: [nil values and Google Translate](https://github.com/glebm/i18n-tasks/issues/85), [config file encoding issue](#82).
|
5
|
+
|
1
6
|
## 0.7.2
|
2
7
|
|
3
8
|
* i18n-tasks now analyses itself! `internal_locale` setting has been added, that controls i18n-tasks reporting language.
|
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.3'
|
29
29
|
```
|
30
30
|
|
31
31
|
Copy default [configuration file](#configuration) (optional):
|
@@ -346,6 +346,14 @@ ignore:
|
|
346
346
|
### Google Translate
|
347
347
|
|
348
348
|
`i18n-tasks translate-missing` requires a Google Translate API key, get it at [Google API Console](https://code.google.com/apis/console).
|
349
|
+
|
350
|
+
Where this key is depends on your Google API console:
|
351
|
+
|
352
|
+
* Old console: API Access -> Simple API Access -> Key for server apps.
|
353
|
+
* New console: Project -> APIS & AUTH -> Credentials -> Public API access -> Key for server applications.
|
354
|
+
|
355
|
+
In both cases, you may need to create the key if it doesn't exist.
|
356
|
+
|
349
357
|
Put the key in `GOOGLE_TRANSLATE_API_KEY` environment variable or in the config file.
|
350
358
|
|
351
359
|
```yaml
|
data/config/i18n-tasks.yml
CHANGED
data/config/locales/en.yml
CHANGED
@@ -57,6 +57,7 @@ en:
|
|
57
57
|
add_missing: add missing keys to locale data
|
58
58
|
remove_unused: remove unused keys
|
59
59
|
eq_base: show translations equal to base value
|
60
|
+
tree_translate: Google Translate a tree to root locales
|
60
61
|
tree_merge: merge trees
|
61
62
|
tree_filter: filter tree by key pattern
|
62
63
|
tree_rename_key: rename tree node
|
@@ -75,8 +76,8 @@ en:
|
|
75
76
|
data_format: 'Data format: %{valid_text}. %{default_text}.'
|
76
77
|
keys: List of keys separated by commas (,), spaces, or newlines.
|
77
78
|
locales_filter: 'Comma-separated list of locale(s) to process. Default: all. Special: base.'
|
78
|
-
locales_to_translate_from: 'Locale to translate from (default: base)'
|
79
79
|
locale: 'Locale. Default: base'
|
80
|
+
locale_to_translate_from: 'Locale to translate from (default: base)'
|
80
81
|
confirm: Confirm automatically
|
81
82
|
nostdin: Do not read from stdin
|
82
83
|
strict: Do not infer dynamic key usage such as `t("category.\#{category.name}")`
|
data/config/locales/ru.yml
CHANGED
@@ -67,6 +67,7 @@ ru:
|
|
67
67
|
gem_path: "показать путь к ruby gem"
|
68
68
|
irb: "начать REPL сессию в контексте i18n-tasks"
|
69
69
|
xlsx_report: "сохранить недостающие и неиспользуемые переводы в Excel-файл"
|
70
|
+
tree_translate: "Перевести дерево при помощи Google Translate на язык корневых узлов"
|
70
71
|
args:
|
71
72
|
default_text: "По умолчанию: %{value}"
|
72
73
|
default_all: "По умолчанию: все"
|
@@ -76,7 +77,7 @@ ru:
|
|
76
77
|
keys: "Список ключей, разделенных запятыми (,), пробелами или символами новой строки."
|
77
78
|
locales_filter: "Список языков для обработки, разделенный запятыми (,). По умолчанию: все.
|
78
79
|
Специальное значение: base."
|
79
|
-
|
80
|
+
locale_to_translate_from: "Язык, с которого переводить (по умолчанию: base)"
|
80
81
|
locale: "Язык. По умолчанию: base"
|
81
82
|
confirm: "Подтвердить автоматом"
|
82
83
|
nostdin: "Не читать дерево из стандартного ввода"
|
@@ -22,16 +22,11 @@ module I18n::Tasks
|
|
22
22
|
cmd :translate_missing,
|
23
23
|
args: '[locale ...]',
|
24
24
|
desc: proc { I18n.t('i18n_tasks.cmd.desc.translate_missing') },
|
25
|
-
opt:
|
26
|
-
cmd_opt(:locale).merge(short: :f, long: :from=, desc: proc {
|
27
|
-
I18n.t('i18n_tasks.cmd.args.desc.locales_to_translate_from') }),
|
28
|
-
cmd_opt(:out_format).except(:short)]
|
25
|
+
opt: cmd_opts(:locales, :locale_to_translate_from) << cmd_opt(:out_format).except(:short)
|
29
26
|
|
30
27
|
def translate_missing(opt = {})
|
31
|
-
|
32
|
-
translated =
|
33
|
-
result.merge! i18n.google_translate_forest i18n.missing_tree(locale, from), from, locale
|
34
|
-
end
|
28
|
+
missing = i18n.missing_diff_forest opt[:locales], opt[:from]
|
29
|
+
translated = i18n.google_translate_forest missing, opt[:from]
|
35
30
|
i18n.data.merge! translated
|
36
31
|
log_stderr I18n.t('i18n_tasks.translate_missing.translated', count: translated.leaves.count)
|
37
32
|
print_forest translated, opt
|
@@ -4,6 +4,18 @@ module I18n::Tasks
|
|
4
4
|
module Tree
|
5
5
|
include Command::Collection
|
6
6
|
|
7
|
+
cmd :tree_translate,
|
8
|
+
args: '[tree]',
|
9
|
+
desc: proc { I18n.t('i18n_tasks.cmd.desc.tree_translate') },
|
10
|
+
opt: cmd_opts(:locale_to_translate_from) << cmd_opt(:data_format).except(:short)
|
11
|
+
|
12
|
+
def tree_translate(opts = {})
|
13
|
+
forest = opt_forest_arg_or_stdin!(opts)
|
14
|
+
from = opts[:from]
|
15
|
+
translated = i18n.google_translate_forest(forest, from)
|
16
|
+
print_forest translated, opts
|
17
|
+
end
|
18
|
+
|
7
19
|
cmd :tree_merge,
|
8
20
|
args: '[tree ...]',
|
9
21
|
desc: proc { I18n.t('i18n_tasks.cmd.desc.tree_merge') },
|
@@ -7,7 +7,7 @@ module I18n::Tasks
|
|
7
7
|
cmd_opt :locales, {
|
8
8
|
short: :l,
|
9
9
|
long: :locales=,
|
10
|
-
desc: I18n.t('i18n_tasks.cmd.args.desc.locales_filter'),
|
10
|
+
desc: proc { I18n.t('i18n_tasks.cmd.args.desc.locales_filter') },
|
11
11
|
conf: {as: Array, delimiter: /\s*[+:,]\s*/, default: 'all', argument: true, optional: false},
|
12
12
|
parse: :parse_locales
|
13
13
|
}
|
@@ -15,11 +15,16 @@ module I18n::Tasks
|
|
15
15
|
cmd_opt :locale, {
|
16
16
|
short: :l,
|
17
17
|
long: :locale=,
|
18
|
-
desc: I18n.t('i18n_tasks.cmd.args.desc.locale'),
|
18
|
+
desc: proc { I18n.t('i18n_tasks.cmd.args.desc.locale') },
|
19
19
|
conf: {default: 'base', argument: true, optional: false},
|
20
20
|
parse: :parse_locale
|
21
21
|
}
|
22
22
|
|
23
|
+
cmd_opt :locale_to_translate_from, cmd_opt(:locale).merge(
|
24
|
+
short: :f,
|
25
|
+
long: :from=,
|
26
|
+
desc: proc { I18n.t('i18n_tasks.cmd.args.desc.locale_to_translate_from') })
|
27
|
+
|
23
28
|
def parse_locales(opt, key = :locales)
|
24
29
|
argv = Array(opt[:arguments]) + Array(opt[key])
|
25
30
|
locales = if argv == ['all'] || argv == 'all' || argv.blank?
|
@@ -4,10 +4,12 @@ require 'i18n/tasks/html_keys'
|
|
4
4
|
|
5
5
|
module I18n::Tasks
|
6
6
|
module GoogleTranslation
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
|
8
|
+
def google_translate_forest(forest, from)
|
9
|
+
forest.inject empty_forest do |result, root|
|
10
|
+
translated = google_translate_list(root.key_values(root: true), to: root.key, from: from)
|
11
|
+
result.merge! Data::Tree::Siblings.from_flat_pairs(translated)
|
12
|
+
end
|
11
13
|
end
|
12
14
|
|
13
15
|
# @param [Array] list of [key, value] pairs
|
@@ -42,7 +44,7 @@ Get the key at https://code.google.com/apis/console.')
|
|
42
44
|
end
|
43
45
|
|
44
46
|
def to_values(list)
|
45
|
-
list.map { |l| dump_value l[1] }.flatten
|
47
|
+
list.map { |l| dump_value l[1] }.flatten.compact
|
46
48
|
end
|
47
49
|
|
48
50
|
def from_values(list, translated_values)
|
@@ -52,21 +54,28 @@ Get the key at https://code.google.com/apis/console.')
|
|
52
54
|
end
|
53
55
|
|
54
56
|
def dump_value(value)
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
case value
|
58
|
+
when Array
|
59
|
+
# dump recursively
|
60
|
+
value.map { |v| dump_value v }
|
61
|
+
when String
|
62
|
+
replace_interpolations value
|
63
|
+
else
|
64
|
+
value
|
60
65
|
end
|
61
66
|
end
|
62
67
|
|
63
68
|
def parse_value(untranslated, each_translated)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
69
|
+
case untranslated
|
70
|
+
when Array
|
71
|
+
# implode array
|
72
|
+
untranslated.map { |from| parse_value(from, each_translated) }
|
73
|
+
when String
|
74
|
+
restore_interpolations untranslated, each_translated.next
|
75
|
+
when NilClass
|
76
|
+
nil
|
77
|
+
else
|
78
|
+
each_translated.next
|
70
79
|
end
|
71
80
|
end
|
72
81
|
|
data/lib/i18n/tasks/version.rb
CHANGED
@@ -6,12 +6,12 @@ describe 'Google Translation' do
|
|
6
6
|
include I18n::Tasks::GoogleTranslation
|
7
7
|
|
8
8
|
tests = [
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
nil_value_test = ['nil-value-key', nil, nil],
|
10
|
+
text_test = ['key', "Hello - %{user} O'neill!", "Hola - %{user} O'neill!"],
|
11
|
+
html_test = ['html-key.html', "Hello - <b>%{user} O'neill</b>", "Hola - <b>%{user} O'neill</b>"],
|
12
|
+
array_test = ['array-key', ['Hello.', nil, '', 'Goodbye.'], ['Hola.', nil, '', 'Adiós.']]
|
12
13
|
]
|
13
14
|
|
14
|
-
|
15
15
|
if ENV['GOOGLE_TRANSLATE_API_KEY']
|
16
16
|
describe 'real world test' do
|
17
17
|
delegate :i18n_cmd, :i18n_task, :in_test_app_dir, to: :TestCodebase
|
@@ -41,13 +41,14 @@ describe 'Google Translation' do
|
|
41
41
|
in_test_app_dir do
|
42
42
|
task.data[:en] = build_tree('en' => {
|
43
43
|
'common' => {
|
44
|
-
'a'
|
45
|
-
'hello'
|
46
|
-
'hello_html'
|
47
|
-
'array_key'
|
44
|
+
'a' => 'λ',
|
45
|
+
'hello' => text_test[1],
|
46
|
+
'hello_html' => html_test[1],
|
47
|
+
'array_key' => array_test[1],
|
48
|
+
'nil-value-key' => nil_value_test[1]
|
48
49
|
}
|
49
50
|
})
|
50
|
-
task.data[:es] = build_tree('es' =>{
|
51
|
+
task.data[:es] = build_tree('es' => {
|
51
52
|
'common' => {
|
52
53
|
'a' => 'λ',
|
53
54
|
}
|
@@ -57,6 +58,7 @@ describe 'Google Translation' do
|
|
57
58
|
expect(task.t('common.hello', 'es')).to eq(text_test[2])
|
58
59
|
expect(task.t('common.hello_html', 'es')).to eq(html_test[2])
|
59
60
|
expect(task.t('common.array_key', 'es')).to eq(array_test[2])
|
61
|
+
expect(task.t('nil-value-key', 'es')).to eq(nil_value_test[2])
|
60
62
|
expect(task.t('common.a', 'es')).to eq('λ')
|
61
63
|
end
|
62
64
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# i18n-tasks finds and manages missing and unused translations
|
1
|
+
# i18n-tasks finds and manages missing and unused translations https://github.com/glebm/i18n-tasks
|
2
2
|
|
3
3
|
base_locale: en
|
4
4
|
## i18n-tasks detects locales automatically from the existing locale files
|
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.3
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: erubis
|
@@ -331,7 +331,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
331
331
|
version: '0'
|
332
332
|
requirements: []
|
333
333
|
rubyforge_project:
|
334
|
-
rubygems_version: 2.
|
334
|
+
rubygems_version: 2.4.1
|
335
335
|
signing_key:
|
336
336
|
specification_version: 4
|
337
337
|
summary: Manage localization and translation with the awesome power of static analysis
|