bing_translate_yaml 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tasks/translate_task.rake +12 -10
- metadata +21 -6
@@ -1,11 +1,17 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'rexml/document'
|
3
|
+
require 'bing_translator'
|
3
4
|
|
4
5
|
desc "Translate your YAML files using Bing."
|
5
6
|
task :translate => :environment do
|
6
7
|
@from_locale = ENV["from"]
|
8
|
+
raise "need to specify from=<locale>" unless @from_locale
|
9
|
+
|
7
10
|
@to_locale = ENV["to"]
|
8
|
-
|
11
|
+
raise "need to specify to=<locale>" unless @to_locale
|
12
|
+
|
13
|
+
@app_id = ENV["app_id"]
|
14
|
+
raise "need to specify app_id=<Your Bing API key>" unless @app_id
|
9
15
|
|
10
16
|
puts "Translating..."
|
11
17
|
|
@@ -77,17 +83,13 @@ end
|
|
77
83
|
def translate_string(source)
|
78
84
|
return "" unless source
|
79
85
|
|
80
|
-
|
81
|
-
xml = Net::HTTP.get_response(URI.parse(url)).body
|
82
|
-
|
83
|
-
doc = REXML::Document.new(xml)
|
84
|
-
if element = doc.elements["string"]
|
85
|
-
dest = element.text.html_safe.gsub("% {", "%{")
|
86
|
-
else
|
87
|
-
dest = ""
|
88
|
-
end
|
86
|
+
dest = translator.translate(source, :from => @from_locale, :to => @to_locale)
|
89
87
|
|
90
88
|
puts "#{source} => #{dest}"
|
91
89
|
|
92
90
|
dest
|
91
|
+
end
|
92
|
+
|
93
|
+
def translator
|
94
|
+
@translator ||= BingTranslator.new @app_id
|
93
95
|
end
|
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:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Lasse Bunk
|
@@ -15,9 +15,24 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-05-
|
19
|
-
dependencies:
|
20
|
-
|
18
|
+
date: 2012-05-18 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bing_translator
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 27
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
- 2
|
33
|
+
version: 0.0.2
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
21
36
|
description: bing_translate_yaml is a simple Ruby on Rails plugin to translate your YAML files using Bing.
|
22
37
|
email: lassebunk@gmail.com
|
23
38
|
executables: []
|