gtranslate 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README +22 -0
  2. data/lib/gtranslate.rb +22 -0
  3. metadata +62 -0
data/README ADDED
@@ -0,0 +1,22 @@
1
+ Usage:
2
+
3
+ gem "t2etranslator" #include gem
4
+
5
+
6
+
7
+ This will print "love" in tamil as "அன்பு"
8
+
9
+ require "t2etranslator"
10
+ puts Translator.translate("Love");
11
+
12
+ For other language you should pass language code as parameter
13
+ "hi" is code for "hindi"
14
+
15
+ require "t2etranslator"
16
+ puts Translator.translate("Love", "hi");
17
+
18
+ This will print as "प्यार" (pyar)
19
+
20
+ Note: This code translates with use of google translate. Feel free to give suggestion and change code.
21
+
22
+ Email me at: sathia2704@gmail.com
data/lib/gtranslate.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ String.class_eval do
5
+ def translate_to language
6
+ begin
7
+ code = code_for language
8
+ page = Nokogiri::HTML(open(URI.parse(URI.encode("http://translate.google.com/?langpair=en|#{code}&text=#{self}"))))
9
+ result = page.search("#result_box")
10
+ result.text
11
+ rescue => e
12
+ puts e
13
+ puts 'Some problem to translate. Please try again later'
14
+ exit
15
+ end
16
+ end
17
+ def code_for language
18
+ language = language.downcase
19
+ language_codes = {'tamil' => 'ta', 'bengali' => 'bn', 'telugu' => 'te', 'malayalam' => 'ml', 'kannada' => 'kn', 'gujarati' => 'gu', 'hindi' => 'hi'}
20
+ language_codes[language]
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gtranslate
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - sathia
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Translate your english scripts to any language using ruby
31
+ email: sathia2704@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - lib/gtranslate.rb
37
+ - README
38
+ homepage: http://rubygems.org/gems/t2etranslator
39
+ licenses: []
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.25
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: GTranslate
62
+ test_files: []