yaml-translator 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/example/google_translate.rb +1 -1
- data/lib/yaml-translator/translator.rb +10 -1
- data/lib/yaml-translator/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87f402e2c73687e9c7d96856a15b996719ac1457
|
4
|
+
data.tar.gz: 4f052f264ba169fb131f21067e72a391566aa008
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 412b6a2821b6a5fa9dd360d0a629b42b3c595321223bcf743f5b3e0cf6efd7ed7ce9123f5c631f6cc0a9c311333863518437d49fb2f5914cea3ea3d7062509fe
|
7
|
+
data.tar.gz: 066b857483e4a93d4b79490690272e01e6edb8515f0676ff791761a9e4d8883027bc64912cdc507044b7991dac81870ba655ed704f6bd95049b61d08885c27ce
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -15,10 +15,10 @@ require 'yaml-translator'
|
|
15
15
|
|
16
16
|
adapter = ::YamlTranslator::Adapters::GoogleTranslateAdapter.new(ENV['GOOGLE_TRANSLATE_API_KEY'])
|
17
17
|
|
18
|
-
yaml =
|
18
|
+
yaml = "#{dir}/en.yml"
|
19
19
|
translator = ::YamlTranslator::Translator.new(adapter)
|
20
20
|
|
21
|
-
result = translator.
|
21
|
+
result = translator.translate_file(yaml, to: :ja)
|
22
22
|
result.save_to('/path/to/directory') # Write a ja.yml
|
23
23
|
result.save # Write a ja.yml (current directory)
|
24
24
|
```
|
data/example/google_translate.rb
CHANGED
@@ -6,7 +6,7 @@ require 'yaml-translator'
|
|
6
6
|
dir = File.dirname(__FILE__)
|
7
7
|
adapter = ::YamlTranslator::Adapters::GoogleTranslateAdapter.new(ENV['GOOGLE_TRANSLATE_API_KEY'])
|
8
8
|
translator = ::YamlTranslator::Translator.new(adapter)
|
9
|
-
result = translator.
|
9
|
+
result = translator.translate_file("#{dir}/en.yml", to: :ja)
|
10
10
|
|
11
11
|
p result.to_s
|
12
12
|
p result.save_to(dir)
|
@@ -10,11 +10,20 @@ module YamlTranslator
|
|
10
10
|
# Translate target
|
11
11
|
#
|
12
12
|
# @param [Hash] values Hash of translate target
|
13
|
-
# @return [
|
13
|
+
# @return [TranslatedResult] translated result
|
14
14
|
def translate(values, options={})
|
15
15
|
TranslatedResult.new(rebuild(translate_tree(flatten(values), options)), options[:to])
|
16
16
|
end
|
17
17
|
|
18
|
+
# Translate target file
|
19
|
+
#
|
20
|
+
# @param [Hash] file YAML file of translate target
|
21
|
+
# @return [TranslatedResult] translated result
|
22
|
+
def translate_file(file, options={})
|
23
|
+
yaml = YAML.load(File.open(file, &:read))
|
24
|
+
translate(yaml)
|
25
|
+
end
|
26
|
+
|
18
27
|
private
|
19
28
|
|
20
29
|
# Translate target
|