i18n-tasks 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03263ddf669098e8580e4656d41e7b15d2ba5721
4
- data.tar.gz: ae4bcf9dee99a2e6cb19e6ee2d52cc34b281e335
3
+ metadata.gz: 334c00605d3e55a82e36c72359bdf31a17bd54f2
4
+ data.tar.gz: f0240ff3e7452b1509c18cc0b5c33f6eecd8b7ec
5
5
  SHA512:
6
- metadata.gz: 69aff7e4e6369e2fe1c622255bfda9290a3141eeb28be0fa368af1be3f568e1934d65ee77e66d180025bd2c9279ca4a0aff73e7135fa21b538b1a00941e26540
7
- data.tar.gz: e21ca15833a7a7822ce166599863e3d6184cdc7a9535740554cf7e7b29a10e7c013cb34a3be4b54d6a8be4a5d53fb18a1038a9d3a2ce4bbeef06664e2d5f8a1e
6
+ metadata.gz: 53a6c2668b4a31bc8049b2c0b08ea4c76aa0e30e6740c83a70878820965a77efa8d47f2639407b21e8b306ea6a9e581c344933b484f737a650dd4f3df0991392
7
+ data.tar.gz: 9a50045d591c8aa773e31e2223739eb814ab9010e8a7d6f9b603c76fe0bbd791c643ebbbd8acc1954eec3b241febefaf652a4f67a7514b59552dacaf68d2f9fb
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.6.1
2
+
3
+ * Fix Google Translate issue with plural keys and missing billing info error
4
+
1
5
  ## 0.6.0
2
6
 
3
7
  * New output format options for reports: yaml, json, and inspect.
data/README.md CHANGED
@@ -127,7 +127,7 @@ Inspect configuration with `i18n-tasks config`.
127
127
  Install the default config file with:
128
128
 
129
129
  ```bash
130
- cp $(i18n-tasks gem-path)/templates/config/i18n-tasks.yml spec/
130
+ cp $(i18n-tasks gem-path)/templates/config/i18n-tasks.yml config/
131
131
  ```
132
132
 
133
133
  ### Locales
@@ -20,7 +20,7 @@ module I18n::Tasks
20
20
  from = opts[:from] || base_locale
21
21
  locales = (Array(opts[:locales]).presence || self.locales) - [from]
22
22
  locales.each do |locale|
23
- keys = missing_tree(locale, from).key_names.map(&:to_s)
23
+ keys = missing_tree(locale, from, false).key_names.map(&:to_s)
24
24
  values = google_translate(keys.zip(keys.map(&t_proc(from))), to: locale, from: from).map(&:last)
25
25
 
26
26
  data[locale] = data[locale].merge! Data::Tree::Node.new(
@@ -1,51 +1,54 @@
1
1
  # coding: utf-8
2
2
  require 'easy_translate'
3
3
 
4
- module I18n::Tasks::GoogleTranslation
5
- # @param [Array] list of [key, value] pairs
6
- def google_translate(list, opts)
7
- return [] if list.empty?
8
- opts = opts.dup
9
- if !opts[:key] && (key = translation_config[:api_key]).present?
10
- opts[:key] = key
11
- end
12
- if opts[:key].blank?
13
- warn_missing_api_key
14
- return []
4
+ module I18n::Tasks
5
+ module GoogleTranslation
6
+ # @param [Array] list of [key, value] pairs
7
+ def google_translate(list, opts)
8
+ return [] if list.empty?
9
+ opts = opts.dup
10
+ if !opts[:key] && (key = translation_config[:api_key]).present?
11
+ opts[:key] = key
12
+ end
13
+ if opts[:key].blank?
14
+ warn_missing_api_key
15
+ return []
16
+ end
17
+ key_idx = {}
18
+ list.each_with_index { |k_v, i| key_idx[k_v[0]] = i }
19
+ list.group_by { |k_v|
20
+ k_v[0].end_with?('_html'.freeze)
21
+ }.map do |html, slice|
22
+ t_opts = opts.merge(html ? {html: true} : {format: 'text'})
23
+ fetch_google_translations slice, t_opts
24
+ end.reduce(:+).tap { |l|
25
+ l.sort! { |a, b| key_idx[a[0]] <=> key_idx[b[0]] }
26
+ }
15
27
  end
16
- key_idx = {}
17
- list.each_with_index { |k_v, i| key_idx[k_v[0]] = i}
18
- list.group_by { |k_v|
19
- k_v[0].end_with?('_html'.freeze)
20
- }.map do |html, slice|
21
- t_opts = opts.merge(html ? {html: true} : {format: 'text'})
22
- fetch_google_translations slice, t_opts
23
- end.reduce(:+).tap { |l|
24
- l.sort! { |a, b| key_idx[a[0]] <=> key_idx[b[0]] }
25
- }
26
- end
27
28
 
28
- INTERPOLATION_KEY_RE = /%\{[^}]+\}/
29
- UNTRANSLATABLE_STRING = 'zxzxzx'
29
+ INTERPOLATION_KEY_RE = /%\{[^}]+\}/
30
+ UNTRANSLATABLE_STRING = 'zxzxzx'
30
31
 
31
- def fetch_google_translations(list, opts)
32
- translated = EasyTranslate.translate(list.map { |l| l[1].gsub(INTERPOLATION_KEY_RE, UNTRANSLATABLE_STRING) }, opts)
33
- if translated.blank?
34
- raise CommandError.new('Google Translate returned no results. Make sure billing information is set at https://code.google.com/apis/console.')
35
- end
36
- translated.each_with_index { |translation, i|
37
- if (original = list[i][1]) =~ INTERPOLATION_KEY_RE
38
- interpolation_keys = original.scan(INTERPOLATION_KEY_RE)
39
- i = -1; translation.gsub!(Regexp.new(UNTRANSLATABLE_STRING, Regexp::IGNORECASE)) { interpolation_keys[i += 1] }
32
+ def fetch_google_translations(list, opts)
33
+ translated = EasyTranslate.translate(list.map { |l| l[1].gsub(INTERPOLATION_KEY_RE, UNTRANSLATABLE_STRING) }, opts)
34
+ if translated.blank?
35
+ raise CommandError.new('Google Translate returned no results. Make sure billing information is set at https://code.google.com/apis/console.')
40
36
  end
41
- }
42
- list.map(&:first).zip(translated)
43
- end
37
+ translated.each_with_index { |translation, i|
38
+ if (original = list[i][1]) =~ INTERPOLATION_KEY_RE
39
+ interpolation_keys = original.scan(INTERPOLATION_KEY_RE)
40
+ i = -1
41
+ translation.gsub!(Regexp.new(UNTRANSLATABLE_STRING, Regexp::IGNORECASE)) { interpolation_keys[i += 1] }
42
+ end
43
+ }
44
+ list.map(&:first).zip(translated)
45
+ end
44
46
 
45
- private
47
+ private
46
48
 
47
- def warn_missing_api_key
48
- $stderr.puts Term::ANSIColor.red Term::ANSIColor.yellow 'Set Google API key via GOOGLE_TRANSLATE_API_KEY environmnet variable or translation.api_key in config/i18n-tasks.yml.
49
+ def warn_missing_api_key
50
+ $stderr.puts Term::ANSIColor.red Term::ANSIColor.yellow 'Set Google API key via GOOGLE_TRANSLATE_API_KEY environmnet variable or translation.api_key in config/i18n-tasks.yml.
49
51
  Get the key at https://code.google.com/apis/console.'
52
+ end
50
53
  end
51
54
  end
@@ -50,19 +50,19 @@ module I18n::Tasks
50
50
  end
51
51
  end
52
52
 
53
- def missing_tree(locale, compared_to)
53
+ def missing_tree(locale, compared_to, collapse_plural = true)
54
54
  if locale == compared_to
55
55
  missing_used_tree locale
56
56
  else
57
- missing_diff_tree locale, compared_to
57
+ missing_diff_tree locale, compared_to, collapse_plural
58
58
  end
59
59
  end
60
60
 
61
61
  # keys present in compared_to, but not in locale
62
- def missing_diff_tree(locale, compared_to = base_locale)
62
+ def missing_diff_tree(locale, compared_to = base_locale, collapse_plural = true)
63
63
  data[compared_to].select_keys { |key, _node|
64
64
  locale_key_missing?(locale, key)
65
- }.set_root_key(locale, type: :missing_diff).tap { |t| collapse_plural_nodes!(t) }
65
+ }.set_root_key(locale, type: :missing_diff).tap { |t| collapse_plural_nodes!(t) if collapse_plural }
66
66
  end
67
67
 
68
68
  # keys used in the code missing translations in locale
@@ -1,6 +1,6 @@
1
1
  # coding: utf-8
2
2
  module I18n
3
3
  module Tasks
4
- VERSION = '0.6.0'
4
+ VERSION = '0.6.1'
5
5
  end
6
6
  end
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.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - glebm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-15 00:00:00.000000000 Z
11
+ date: 2014-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: erubis