idiom 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.3.0
@@ -0,0 +1,34 @@
1
+ zh-Hant-TW: zh-TW
2
+ zh-Hant-HK: zh-CN
3
+ es-US: es
4
+ it-IT: it
5
+ id-ID: id
6
+ fr-CA: fr
7
+ en-IN: en
8
+ en-GB: en
9
+ es-MX: es
10
+ da-DK: da
11
+ ru-RU: ru
12
+ th-TH: th
13
+ sv-SE: sv
14
+ fr-FR: fr
15
+ es-ES: es
16
+ en-US: en
17
+ en-SG: en
18
+ en-CA: en
19
+ en-AU: en
20
+ de-DE: de
21
+ zh-Hans-CN: zh-Hans
22
+ pt-BR: pt-BR
23
+ ko-KR: ko
24
+ en-AA: en
25
+ vi-VN: vi
26
+ es-AR: es
27
+ en-NZ: en
28
+ en-MY: en
29
+ ja-JP: ja
30
+ en-PH: en
31
+ el-GR: el
32
+ fi-FI: fi
33
+ nl-NL: nl
34
+ ro-RO: ro
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{idiom}
8
- s.version = "0.2.2"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jeff Coleman"]
12
- s.date = %q{2011-07-05}
12
+ s.date = %q{2011-07-06}
13
13
  s.default_executable = %q{idiom}
14
14
  s.description = %q{Takes a set of keys in Yaml format and translates them through Google Translate.}
15
15
  s.email = %q{progressions@gmail.com}
@@ -27,9 +27,11 @@ Gem::Specification.new do |s|
27
27
  "Rakefile",
28
28
  "VERSION",
29
29
  "bin/idiom",
30
+ "config/locales.yml",
30
31
  "idiom.gemspec",
31
32
  "lib/idiom.rb",
32
33
  "lib/idiom/base.rb",
34
+ "lib/idiom/microsoft_translator.rb",
33
35
  "lib/idiom/yaml.rb",
34
36
  "lib/idiom/yrb.rb",
35
37
  "spec/idiom_spec.rb",
@@ -10,6 +10,7 @@ require 'timer'
10
10
  require 'yrb'
11
11
  require 'yaml'
12
12
 
13
+ require 'idiom/microsoft_translator'
13
14
  require 'idiom/base'
14
15
  require 'idiom/yrb'
15
16
  require 'idiom/yaml'
@@ -41,6 +41,7 @@ module Idiom #:nodoc:
41
41
  #
42
42
 
43
43
  LOCALES = YAML.load_file("./config/locales.yml")
44
+ CONFIG = YAML.load_file("./config/idiom.yml")
44
45
 
45
46
  # locales
46
47
 
@@ -311,13 +312,23 @@ module Idiom #:nodoc:
311
312
  $stdout.puts("Translating #{value} into #{lang}...")
312
313
  code = LOCALES[lang]
313
314
  value = pre_process(value, lang)
314
- translation = Translate.t(value, "ENGLISH", code)
315
+
316
+ translation = do_translate(value, code)
317
+
315
318
  value = post_process(translation, lang)
316
319
  $stdout.puts("value: #{value}")
317
- sleep(5)
318
320
  value
319
321
  end
320
322
 
323
+ def do_translate(value, code)
324
+ if CONFIG["library"].to_s.downcase == "google"
325
+ Translate.t(value, "ENGLISH", code)
326
+ sleep(5)
327
+ else
328
+ MicrosoftTranslator.t(value, code)
329
+ end
330
+ end
331
+
321
332
  def format(key, value)
322
333
  raise "Define in child"
323
334
  end
@@ -330,4 +341,4 @@ module Idiom #:nodoc:
330
341
  line =~ /^[\s]*#/
331
342
  end
332
343
  end
333
- end
344
+ end
@@ -0,0 +1,18 @@
1
+ class MicrosoftTranslator
2
+ CONFIG = YAML.load_file("./config/idiom.yml")
3
+
4
+ class << self
5
+ def t(value, code)
6
+ value = URI.encode(value)
7
+ # "http://api.microsofttranslator.com/V2/Http.svc/Translate?to=#{code}&text=#{}&appId=2CEF8B6B9CA38C6C8355B154C760C28A66E4339F"
8
+
9
+ appId = CONFIG["appId"]
10
+ result = Net::HTTP.get(URI.parse("http://api.microsofttranslator.com/V2/Http.svc/Translate?to=#{code}&text=#{value}&appId=#{appId}"))
11
+
12
+ if result =~ /<string xmlns=\"http:\/\/schemas.microsoft.com\/2003\/10\/Serialization\/\">(.*)<\/string>/
13
+ output = $1
14
+ end
15
+ output.to_s
16
+ end
17
+ end
18
+ end
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
9
- - 2
10
- version: 0.2.2
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeff Coleman
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-05 00:00:00 -05:00
18
+ date: 2011-07-06 00:00:00 -05:00
19
19
  default_executable: idiom
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -196,9 +196,11 @@ files:
196
196
  - Rakefile
197
197
  - VERSION
198
198
  - bin/idiom
199
+ - config/locales.yml
199
200
  - idiom.gemspec
200
201
  - lib/idiom.rb
201
202
  - lib/idiom/base.rb
203
+ - lib/idiom/microsoft_translator.rb
202
204
  - lib/idiom/yaml.rb
203
205
  - lib/idiom/yrb.rb
204
206
  - spec/idiom_spec.rb