bing_translate_yaml 0.1.1 → 0.1.2

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.
Files changed (2) hide show
  1. data/lib/tasks/translate_task.rake +10 -13
  2. metadata +3 -3
@@ -3,38 +3,35 @@ require 'rexml/document'
3
3
 
4
4
  desc "Translate your YAML files using Bing."
5
5
  task :translate => :environment do
6
- @source_locale = ENV["source"]
7
- @dest_locale = ENV["destination"]
6
+ @from_locale = ENV["from"]
7
+ @to_locale = ENV["to"]
8
8
  @app_id = ENV["app_id"] || "TWwfmo09qPdsxVfnXUMCRHAyk2dGOaodKYVOvbyu3m5Y*"
9
9
 
10
10
  puts "Translating..."
11
11
 
12
- source_locale = ENV["source"]
13
- dest_locale = ENV["destination"]
14
-
15
- source_path = "#{Rails.root}/config/locales/#{@source_locale}.yml"
16
- dest_path = "#{Rails.root}/config/locales/#{@dest_locale}.yml"
12
+ source_path = "#{Rails.root}/config/locales/#{@from_locale}.yml"
13
+ dest_path = "#{Rails.root}/config/locales/#{@to_locale}.yml"
17
14
 
18
15
  if File.exists?(source_path)
19
16
  source_yaml = YAML::load(File.open(source_path))
20
- source = source_yaml ? source_yaml[source_locale] || {} : {}
17
+ source = source_yaml ? source_yaml[@from_locale] || {} : {}
21
18
  else
22
19
  source = {}
23
20
  end
24
21
 
25
22
  if File.exists?(dest_path)
26
23
  dest_yaml = YAML::load(File.open(dest_path))
27
- dest = dest_yaml ? dest_yaml[dest_locale] || {} : {}
24
+ dest = dest_yaml ? dest_yaml[@to_locale] || {} : {}
28
25
  else
29
26
  dest = {}
30
27
  end
31
28
 
32
- source = source_yaml ? source_yaml[source_locale] || {} : {}
33
- dest = dest_yaml ? dest_yaml[dest_locale] || {} : {}
29
+ source = source_yaml ? source_yaml[@from_locale] || {} : {}
30
+ dest = dest_yaml ? dest_yaml[@to_locale] || {} : {}
34
31
 
35
32
  translated = translate_hash(source)
36
33
 
37
- out = { dest_locale => translated.deep_merge(dest) }
34
+ out = { @to_locale => translated.deep_merge(dest) }
38
35
 
39
36
  File.open(dest_path, 'w') {|f| YAML.dump(out, f) }
40
37
 
@@ -78,7 +75,7 @@ end
78
75
  def translate_string(source)
79
76
  return "" unless source
80
77
 
81
- url = "http://api.microsofttranslator.com/v2/Http.svc/Translate?appId=#{@app_id}&text=#{CGI::escape(source)}&from=#{@source_locale}&to=#{@dest_locale}"
78
+ url = "http://api.microsofttranslator.com/v2/Http.svc/Translate?appId=#{@app_id}&text=#{CGI::escape(source)}&from=#{@from_locale}&to=#{@to_locale}"
82
79
  xml = Net::HTTP.get_response(URI.parse(url)).body
83
80
 
84
81
  doc = REXML::Document.new(xml)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bing_translate_yaml
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Lasse Bunk