shvets-google_translate 0.5.9 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -20,3 +20,7 @@
20
20
  == Version 0.5.9
21
21
 
22
22
  * Adding alias: "t" for "translate" command
23
+
24
+ == Version 0.6.1
25
+
26
+ * Adding error handling
data/bin/translate CHANGED
@@ -8,6 +8,7 @@ require 'google_translate'
8
8
  #$KCODE='u'
9
9
 
10
10
  class Translate
11
+
11
12
  USAGE= <<-TEXT
12
13
  Usage:
13
14
  translate list - displays the list of supported languages
@@ -62,7 +63,11 @@ class Translate
62
63
  from = @translator.detect_language(from_text)['language']
63
64
  to = $1
64
65
 
65
- display(@translator.translate(from.to_sym, to.to_sym, from_text))
66
+ begin
67
+ display(@translator.translate(from.to_sym, to.to_sym, from_text))
68
+ rescue Exception => e
69
+ puts "Error: " + e.message
70
+ end
66
71
  end
67
72
  end
68
73
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{google_translate}
5
- s.version = "0.5.9"
5
+ s.version = "0.6.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
 
@@ -29,4 +29,6 @@ Gem::Specification.new do |s|
29
29
  s.platform = Gem::Platform::RUBY
30
30
  s.requirements = ["none"]
31
31
  s.bindir = "bin"
32
+
33
+ s.add_dependency("json_pure", ">= 1.1.4")
32
34
  end
@@ -5,28 +5,21 @@ require 'cgi'
5
5
  require 'json'
6
6
 
7
7
  module Google
8
- class Language
9
- attr_reader :name, :code
10
-
11
- def initialize(name, code)
12
- @name = name
13
- @code = code
14
- end
15
-
8
+ Language = Struct.new(:name, :code) do
16
9
  def to_s
17
- "(" + @code + ": " + @name + ")"
10
+ "(" + code + ": " + name + ")"
18
11
  end
19
12
  end
20
13
 
21
14
  class Translator
22
- class MissingFromLanguage < Exception; end
23
- class MissingToLanguage < Exception; end
24
- class MissingTextLanguage < Exception; end
25
- class TranslateServerIsDown < Exception; end
26
- class InvalidResponse < Exception; end
27
- class MissingText < Exception; end
28
- class MissingTestText < MissingText; end
29
-
15
+ def self.Exception(*names)
16
+ cl = Module === self ? self : Object
17
+ names.each {|n| cl.const_set(n, Class.new(Exception))}
18
+ end
19
+
20
+ Exception :MissingFromLanguage, :MissingToLanguage, :MissingTextLanguage,
21
+ :TranslateServerIsDown, :InvalidResponse, :MissingText, :MissingTestText
22
+
30
23
  URL_STRING = "http://ajax.googleapis.com/ajax/services/language/"
31
24
  URL2_STRING = "http://translate.google.com"
32
25
 
@@ -135,23 +128,6 @@ module Google
135
128
 
136
129
  languages
137
130
  end
138
-
139
- def encode_text text
140
- s = ''
141
- text.unpack("U*").each do |ch|
142
- if (1072..1087).include? ch
143
- s << (ch-912).chr
144
- elsif (1088..1103).include? ch
145
- s << (ch-864).chr
146
- elsif (1020..1071).include? ch
147
- s << (ch-892).chr
148
- else
149
- s << ch
150
- end
151
- end
152
-
153
- s
154
- end
155
131
  end
156
132
 
157
133
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shvets-google_translate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Shvets
@@ -11,8 +11,17 @@ cert_chain: []
11
11
 
12
12
  date: 2009-01-21 00:00:00 -08:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json_pure
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.1.4
24
+ version:
16
25
  description: Simple client for Google Translate API.
17
26
  email: alexander.shvets@gmail.com
18
27
  executables: