sishen-rtranslate 1.4 → 1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ V1.5 Oct 31th, 2010
2
+ * Compatible with ActiveSupport 3.0
3
+
1
4
  V1.3 Dec 18th, 2009
2
5
  * Enable the translation for the long string which is supposed to be more than 500 characters. The lib will split the text into several groups 500 by 500 and then join the response translated text together.
3
6
 
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ begin
10
10
  p.email = 'yedingding@gmail.com'
11
11
  p.homepage = 'http://github.com/sishen/rtranslate'
12
12
  p.summary = 'Google translate ruby client api'
13
- p.description = 'A simple, unofficial, ruby client API for using Google Translate.'
13
+ p.description = 'A simple, unofficial, ruby client API for using Google Translate.'
14
14
  p.add_dependency 'json', '>= 1.1.3'
15
15
  p.add_dependency 'activesupport', '>= 2.2.0'
16
16
  end
@@ -14,10 +14,11 @@ rescue LoadError
14
14
  require 'json'
15
15
  end
16
16
 
17
- $KCODE = 'u'
18
-
17
+ $KCODE = 'u' unless RUBY_VERSION >= "1.9"
18
+
19
19
  unless defined?(ActiveSupport)
20
20
  require 'active_support'
21
+ require 'active_support/core_ext'
21
22
  end
22
23
 
23
24
  include Translate
@@ -67,12 +67,12 @@ module Translate
67
67
  to = Google::Language.abbrev(to)
68
68
  langpair = "#{from}|#{to}"
69
69
 
70
- text.mb_chars.scan(/(.{1,300})/).inject("") do |result, st|
70
+ text.mb_chars.scan(/(.{1,300})/).flatten.inject("") do |result, st|
71
71
  url = "#{GOOGLE_TRANSLATE_URL}?q=#{CGI.escape(st.to_s)}&langpair=#{CGI.escape(langpair)}&v=#{@version}"
72
72
  url << "&key=#{@key}" if @key
73
73
  url << "&userip=#{options[:userip]}" if options[:userip]
74
74
 
75
- result += do_translate(url)
75
+ result += CGI.unescapeHTML(do_translate(url))
76
76
  end
77
77
  else
78
78
  raise UnsupportedLanguagePair, "Translation from '#{from}' to '#{to}' isn't supported yet!"
@@ -8,12 +8,12 @@ class Translate::TranslateTest < Test::Unit::TestCase
8
8
  include Google::Language
9
9
  def test_english_translate
10
10
  assert_equal("مرحبا العالم", Translate.t("Hello world", "ENGLISH", "ARABIC"));
11
- assert_equal("世界您好", Translate.t("Hello world", "ENGLISH", "CHINESE_SIMPLIFIED"));
11
+ assert_equal("你好世界", Translate.t("Hello world", "ENGLISH", "CHINESE_SIMPLIFIED"));
12
12
  assert_equal("Bonjour tout le monde", Translate.t("Hello world", "ENGLISH", "FRENCH"));
13
13
  assert_equal("Hallo Welt", Translate.t("Hello world", "ENGLISH", "GERMAN"));
14
14
  assert_equal("Ciao a tutti", Translate.t("Hello world", "ENGLISH", "ITALIAN"));
15
15
  assert_equal("こんにちは、世界", Translate.t("Hello world", "ENGLISH", "JAPANESE"));
16
- assert_equal("안녕하세요 세상", Translate.t("Hello world", "ENGLISH", "KOREAN"));
16
+ assert_equal("안녕하세요", Translate.t("Hello world", "ENGLISH", "KOREAN"));
17
17
  assert_equal("Olá mundo", Translate.t("Hello world", "ENGLISH", "PORTUGUESE"));
18
18
  assert_equal("Привет мир", Translate.t("Hello world", "ENGLISH", "RUSSIAN"));
19
19
  assert_equal("¡Hola, mundo", Translate.t("Hello world", "ENGLISH", "SPANISH"));
@@ -21,12 +21,12 @@ class Translate::TranslateTest < Test::Unit::TestCase
21
21
 
22
22
  def test_auto_detect_translate
23
23
  assert_equal("مرحبا العالم", Translate.t("Hello world", nil, "ARABIC"));
24
- assert_equal("世界您好", Translate.t("Hello world", nil, "CHINESE_SIMPLIFIED"));
24
+ assert_equal("你好世界", Translate.t("Hello world", nil, "CHINESE_SIMPLIFIED"));
25
25
  assert_equal("Bonjour tout le monde", Translate.t("Hello world", nil, "FRENCH"));
26
26
  assert_equal("Hallo Welt", Translate.t("Hello world", nil, "GERMAN"));
27
27
  assert_equal("Ciao a tutti", Translate.t("Hello world", nil, "ITALIAN"));
28
28
  assert_equal("こんにちは、世界", Translate.t("Hello world", nil, "JAPANESE"));
29
- assert_equal("안녕하세요 세상", Translate.t("Hello world", nil, "KOREAN"));
29
+ assert_equal("안녕하세요", Translate.t("Hello world", nil, "KOREAN"));
30
30
  assert_equal("Olá mundo", Translate.t("Hello world", nil, "PORTUGUESE"));
31
31
  assert_equal("Привет мир", Translate.t("Hello world", nil, "RUSSIAN"));
32
32
  assert_equal("¡Hola, mundo", Translate.t("Hello world", nil, "SPANISH"));
@@ -44,15 +44,15 @@ class Translate::TranslateTest < Test::Unit::TestCase
44
44
  end
45
45
 
46
46
  def test_translate_strings
47
- assert_equal(["", "世界"], Translate::RTranslate.translate_strings(["Hello", "World"], "en", "zh-CN"))
47
+ assert_equal(["你好", "世界"], Translate::RTranslate.translate_strings(["Hello", "World"], "en", "zh-CN"))
48
48
  end
49
49
 
50
50
  def test_translate_string_to_languages
51
- assert_equal(["世界您好", "ハローワールド"], Translate::RTranslate.translate_string_to_languages("Hello World", {:from => "en", :to => ["zh-CN", "ja"]}))
51
+ assert_equal(["你好世界", "ハローワールド"], Translate::RTranslate.translate_string_to_languages("Hello World", {:from => "en", :to => ["zh-CN", "ja"]}))
52
52
  end
53
53
 
54
54
  def test_batch_translate
55
- assert_equal(["世界您好", "ハローワールド"],
55
+ assert_equal(["你好世界", "ハローワールド"],
56
56
  Translate::RTranslate.batch_translate([["Hello World", {:from => "en", :to => "zh-CN"}], ["Hello World", {:from => "en", :to => "ja"}]]))
57
57
  end
58
58
  end
metadata CHANGED
@@ -1,12 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sishen-rtranslate
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
5
4
  prerelease: false
6
5
  segments:
7
6
  - 1
8
- - 4
9
- version: "1.4"
7
+ - 5
8
+ version: "1.5"
10
9
  platform: ruby
11
10
  authors:
12
11
  - Ye Dingding
@@ -14,7 +13,7 @@ autorequire:
14
13
  bindir: bin
15
14
  cert_chain: []
16
15
 
17
- date: 2010-08-31 00:00:00 +08:00
16
+ date: 2010-10-31 00:00:00 +08:00
18
17
  default_executable: rtranslate
19
18
  dependencies:
20
19
  - !ruby/object:Gem::Dependency
@@ -25,7 +24,6 @@ dependencies:
25
24
  requirements:
26
25
  - - ">="
27
26
  - !ruby/object:Gem::Version
28
- hash: 21
29
27
  segments:
30
28
  - 1
31
29
  - 1
@@ -41,7 +39,6 @@ dependencies:
41
39
  requirements:
42
40
  - - ">="
43
41
  - !ruby/object:Gem::Version
44
- hash: 7
45
42
  segments:
46
43
  - 2
47
44
  - 2
@@ -86,7 +83,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
83
  requirements:
87
84
  - - ">="
88
85
  - !ruby/object:Gem::Version
89
- hash: 3
90
86
  segments:
91
87
  - 0
92
88
  version: "0"
@@ -95,7 +91,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
91
  requirements:
96
92
  - - ">="
97
93
  - !ruby/object:Gem::Version
98
- hash: 3
99
94
  segments:
100
95
  - 0
101
96
  version: "0"