gtranslate 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,27 @@
1
+ class Gtranslate
2
+ class << self
3
+ def code_for language
4
+ language = language.downcase
5
+ language_codes = {'tamil' => 'ta', 'bengali' => 'bn', 'telugu' => 'te', 'malayalam' => 'ml', 'kannada' => 'kn', 'gujarati' => 'gu', 'hindi' => 'hi'}
6
+ language_codes[language]
7
+ end
8
+
9
+ def url_for code, text
10
+ "http://translate.google.com/?langpair=en|#{code}&text=#{text}"
11
+ end
12
+
13
+ def api_call_to_google_with language, text
14
+ code = code_for language
15
+ begin
16
+ url = URI.parse(URI.encode(url_for(code, text)))
17
+ Nokogiri::HTML(open(url))
18
+ rescue => e
19
+ puts "[Error]: " + e
20
+ end
21
+ end
22
+
23
+ def parse_result_from_response doc
24
+ doc.search("#result_box").text
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,6 @@
1
+ class String
2
+ def translate_to language
3
+ html_dom_from_google = Gtranslate.api_call_to_google_with language, self
4
+ result = Gtranslate.parse_result_from_response html_dom_from_google
5
+ end
6
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gtranslate
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -35,6 +35,8 @@ extra_rdoc_files: []
35
35
  files:
36
36
  - lib/gtranslate.rb
37
37
  - README
38
+ - lib/gtranslate/string.rb
39
+ - lib/gtranslate/api.rb
38
40
  homepage: http://rubygems.org/gems/t2etranslator
39
41
  licenses: []
40
42
  post_install_message: