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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f6225b723afffaf9bb37987dd1241e9f0fd394d
4
- data.tar.gz: c038b73b182bcc0918a163aaebd8050f488f7e5d
3
+ metadata.gz: 87f402e2c73687e9c7d96856a15b996719ac1457
4
+ data.tar.gz: 4f052f264ba169fb131f21067e72a391566aa008
5
5
  SHA512:
6
- metadata.gz: 74a708f5c97c4fb4018ba50088004a706b65ea84c6d0cb3a5816ccc613dc7200a0d9b5b944788723217e71f8cd63e8f2fe09faa5b5402a10ec9945dd0c0602e2
7
- data.tar.gz: e7a729fd0352030c21fba380c022551a43b360598307bc530901b951f5ed415e21757955305ccb7146ac1db8d0d33db6cb6d16fd0d0e493e23679f2bf9d25d6b
6
+ metadata.gz: 412b6a2821b6a5fa9dd360d0a629b42b3c595321223bcf743f5b3e0cf6efd7ed7ce9123f5c631f6cc0a9c311333863518437d49fb2f5914cea3ea3d7062509fe
7
+ data.tar.gz: 066b857483e4a93d4b79490690272e01e6edb8515f0676ff791761a9e4d8883027bc64912cdc507044b7991dac81870ba655ed704f6bd95049b61d08885c27ce
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yaml-translator (0.1.1)
4
+ yaml-translator (0.2.0)
5
5
  easy_translate
6
6
 
7
7
  GEM
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 = YAML.load(File.open("#{dir}/en.yml", &:read))
18
+ yaml = "#{dir}/en.yml"
19
19
  translator = ::YamlTranslator::Translator.new(adapter)
20
20
 
21
- result = translator.translate(yaml, to: :ja)
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
  ```
@@ -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.translate(YAML.load(File.open("#{dir}/en.yml", &:read)), to: :ja)
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 [Hash] translated hash
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
@@ -1,3 +1,3 @@
1
1
  module YamlTranslator
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaml-translator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noritaka Horio