i18n-tasks 0.2.13 → 0.2.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +9 -0
- data/Gemfile +1 -1
- data/lib/i18n/tasks/configuration.rb +0 -1
- data/lib/i18n/tasks/fill_tasks.rb +3 -2
- data/lib/i18n/tasks/google_translation.rb +22 -5
- data/lib/i18n/tasks/version.rb +1 -1
- data/spec/google_translate_spec.rb +15 -0
- data/spec/relative_keys_spec.rb +1 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 760bba77247fae6727219b0e36b605c01f760dff
|
4
|
+
data.tar.gz: 12e5076cdf6279ae466e8137c84ea7f08f155eb7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 739772e09dde3095da37f5e0e47e53ce03564448479867de3b6b4bc7300d1aad9c331b7182ce28f942e29032b6ba30524e398b627ae04d6ce2a05373c09a321c
|
7
|
+
data.tar.gz: 39e7fad91f6269ab0aff4e60ef9d44a6e48baa34c134b177e21974a2aaf2828382af8b640817e6a53efd482531742bcb788a1ce0d8727cb6d0f661b526acccb1
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## v0.2.14.
|
2
|
+
|
3
|
+
* Google Translate fixes: preserve interpolations, set correct format based on the key (text or html).
|
4
|
+
|
5
|
+
## v0.2.13
|
6
|
+
|
7
|
+
* New setting relative_roots for relative key resolution (default: %w(app/views))
|
8
|
+
* fix google translation attempts to translate non-string keys
|
9
|
+
|
1
10
|
## v0.2.11 .. v0.2.12
|
2
11
|
|
3
12
|
* New task: `i18n:remove_unused`
|
data/Gemfile
CHANGED
@@ -38,7 +38,6 @@ module I18n::Tasks::Configuration
|
|
38
38
|
search_config = (config[:search] || {}).with_indifferent_access
|
39
39
|
search_config.tap do |conf|
|
40
40
|
conf[:paths] = %w(app/) if conf[:paths].blank?
|
41
|
-
conf[:relative_roots] = %w( app/views ) if conf[:relative_roots].blank?
|
42
41
|
conf[:include] = Array(conf[:include]) if conf[:include].present?
|
43
42
|
conf[:exclude] = Array(conf[:exclude])
|
44
43
|
conf[:pattern] = conf[:pattern].present? ? Regexp.new(conf[:pattern]) : DEFAULT_PATTERN
|
@@ -27,8 +27,9 @@ module I18n::Tasks::FillTasks
|
|
27
27
|
tr.present? && tr.is_a?(String)
|
28
28
|
}
|
29
29
|
if blank_keys.present?
|
30
|
-
|
31
|
-
|
30
|
+
data[locale] = data[locale].deep_merge(
|
31
|
+
list_to_tree google_translate(blank_keys.zip(blank_keys.map { |k| t(k) }), to: locale, from: base_locale)
|
32
|
+
)
|
32
33
|
end
|
33
34
|
end
|
34
35
|
end
|
@@ -1,16 +1,33 @@
|
|
1
1
|
require 'easy_translate'
|
2
2
|
|
3
3
|
module I18n::Tasks::GoogleTranslation
|
4
|
-
|
5
|
-
|
4
|
+
# @param [Array] list of [key, value] pairs
|
5
|
+
def google_translate(list, opts)
|
6
|
+
return [] if list.empty?
|
6
7
|
opts = opts.dup
|
7
|
-
if (key = translation_config[:api_key]).present?
|
8
|
-
opts[:key]
|
8
|
+
if !opts[:key] && (key = translation_config[:api_key]).present?
|
9
|
+
opts[:key] = key
|
9
10
|
end
|
10
11
|
if opts[:key].blank?
|
11
12
|
$stderr.puts(Term::ANSIColor.red Term::ANSIColor.yellow 'You may need to provide Google API key as GOOGLE_TRANSLATE_API_KEY or in config/i18n-tasks.yml.
|
12
13
|
You can obtain the key at https://code.google.com/apis/console.')
|
13
14
|
end
|
14
|
-
|
15
|
+
list.group_by { |k_v| k_v[0].end_with?('_html'.freeze) ? opts.merge(html: true) : opts.merge(format: 'text') }.map do |opts, strings|
|
16
|
+
fetch_google_translations(strings, opts)
|
17
|
+
end.reduce(:+)
|
18
|
+
end
|
19
|
+
|
20
|
+
INTERPOLATION_KEY_RE = /%\{[^}]+\}/
|
21
|
+
UNTRANSLATABLE_STRING = 'zxzxzx'
|
22
|
+
|
23
|
+
def fetch_google_translations(list, opts)
|
24
|
+
translated = EasyTranslate.translate(list.map { |l| l[1].gsub(INTERPOLATION_KEY_RE, UNTRANSLATABLE_STRING) }, opts)
|
25
|
+
translated.each_with_index { |translation, i|
|
26
|
+
if (original = list[i][1]) =~ INTERPOLATION_KEY_RE
|
27
|
+
interpolation_keys = original.scan(INTERPOLATION_KEY_RE)
|
28
|
+
i = -1; translation.gsub!(UNTRANSLATABLE_STRING) { interpolation_keys[i += 1] }
|
29
|
+
end
|
30
|
+
}
|
31
|
+
list.map(&:first).zip(translated)
|
15
32
|
end
|
16
33
|
end
|
data/lib/i18n/tasks/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Google Translation' do
|
4
|
+
include I18n::Tasks::GoogleTranslation
|
5
|
+
|
6
|
+
if ENV['GOOGLE_TRANSLATE_API_KEY']
|
7
|
+
context 'real world test' do
|
8
|
+
it 'works' do
|
9
|
+
google_translate(
|
10
|
+
[['common.hello', "Hello, %{user}!"]], from: :en, to: :es, key: ENV['GOOGLE_TRANSLATE_API_KEY']
|
11
|
+
).should == [['common.hello', 'Hola, %{user}!']]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/relative_keys_spec.rb
CHANGED
@@ -12,8 +12,7 @@ describe 'Relative keys' do
|
|
12
12
|
|
13
13
|
context 'custom roots' do
|
14
14
|
it 'works' do
|
15
|
-
task.
|
16
|
-
task.absolutize_key('.title', 'app/views-mobile/movies/show.html.slim').should == 'movies.show.title'
|
15
|
+
task.absolutize_key('.title', 'app/views-mobile/movies/show.html.slim', %w(app/views-mobile)).should == 'movies.show.title'
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
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.2.
|
4
|
+
version: 0.2.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- glebm
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -224,6 +224,7 @@ files:
|
|
224
224
|
- spec/fixtures/app/views/index.html.slim
|
225
225
|
- spec/fixtures/app/views/relative/index.html.slim
|
226
226
|
- spec/fixtures/config/i18n-tasks.yml
|
227
|
+
- spec/google_translate_spec.rb
|
227
228
|
- spec/i18n_tasks_spec.rb
|
228
229
|
- spec/key_pattern_matching_spec.rb
|
229
230
|
- spec/readme_spec.rb
|
@@ -268,6 +269,7 @@ test_files:
|
|
268
269
|
- spec/fixtures/app/views/index.html.slim
|
269
270
|
- spec/fixtures/app/views/relative/index.html.slim
|
270
271
|
- spec/fixtures/config/i18n-tasks.yml
|
272
|
+
- spec/google_translate_spec.rb
|
271
273
|
- spec/i18n_tasks_spec.rb
|
272
274
|
- spec/key_pattern_matching_spec.rb
|
273
275
|
- spec/readme_spec.rb
|