rsay 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2008 ETOZZATO-MEKDIGITAL
2
+ Permission is hereby granted, free of charge, to any person obtaining
3
+ a copy of this software and associated documentation files (the
4
+ "Software"), to deal in the Software without restriction, including
5
+ without limitation the rights to use, copy, modify, merge, publish,
6
+ distribute, sublicense, and/or sell copies of the Software, and to
7
+ permit persons to whom the Software is furnished to do so, subject to
8
+ the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be
11
+ included in all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
17
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,11 @@
1
+ == RSAY 1.0.0 ==
2
+ This is a remake and fusion of code and ideas from rtranslate by YeDingding?, rbabel by Sharon Rosner and google-translate-api by Dookie.
3
+
4
+ Dookie implemented a JSON parser for the googleapis translation service but put that in a script, both YeDingding? and Sharon Rosner have a gem that parses the html restult of the web interface, leading to immediate spam block by google.
5
+
6
+ same syntax of rsay:
7
+
8
+ require "rsay"
9
+ result = Translate.t("Hello my Friend", Language::ENGLISH, Language::ITALIAN)
10
+
11
+ $rsay -f en -t it 'Hello my Friend!'
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File::join(File::dirname(File::dirname(__FILE__)), "lib"))
4
+
5
+ require 'rubygems'
6
+ require 'rsay'
7
+ require 'optparse'
8
+
9
+ options = {}
10
+ opts = OptionParser.new do |opts|
11
+ opts.banner = <<-EOF
12
+ Usage:
13
+ rsay -f lang -t lang text
14
+ EOF
15
+
16
+ opts.on("-fLANG", "--from LANG", "From Language LANG") do |x|
17
+ options[:from] = x
18
+ end
19
+
20
+ opts.on("-tLANG", "--to LANG", "To Language LANG") do |x|
21
+ options[:to] = x
22
+ end
23
+
24
+ opts.on("-h", "--help", "Show this message") do
25
+ puts opts
26
+ exit
27
+ end
28
+ end
29
+
30
+ opts.parse!(ARGV)
31
+ text = ARGV.shift
32
+
33
+ if options[:from].nil? || options[:to].nil? || text.empty?
34
+ puts opts
35
+ exit
36
+ end
37
+
38
+ STDOUT.puts(Translate.t(text, options[:from], options[:to]))
@@ -0,0 +1,18 @@
1
+ require 'rsay/language.rb'
2
+ require 'rsay/rsay.rb'
3
+ require 'rubygems'
4
+ require 'net/http'
5
+ require 'json'
6
+ require 'cgi'
7
+ require 'uri'
8
+ require 'htmlentities'
9
+
10
+ include Translate
11
+ def Translate.t(text, from, to)
12
+ begin
13
+ RSay.translate(text, from, to)
14
+ rescue
15
+ "Error: " + $!
16
+ end
17
+ end
18
+
@@ -0,0 +1,27 @@
1
+ module Translate
2
+ module Language
3
+ ARABIC = 'ar'
4
+ CHINESE = 'zh'
5
+ CHINESE_SIMPLIFIED = 'zh-CN'
6
+ CHINESE_TRADITIONAL = 'zh-TW'
7
+ DUTCH = 'nl'
8
+ ENGLISH = 'en'
9
+ FRENCH = 'fr'
10
+ GERMAN = 'de'
11
+ GREEK = 'el'
12
+ ITALIAN = 'it'
13
+ JAPANESE = 'ja'
14
+ KOREAN = 'ko'
15
+ PORTUGUESE = 'pt'
16
+ RUSSIAN = 'ru'
17
+ SPANISH = 'es'
18
+ SWEDISH = 'sv'
19
+
20
+ AVAILABLE_PAIR = ["ar|en", "zh|en", "zh-CN|zh-TW", "zh-TW|zh-CN", "nl|en", "en|ar", "en|zh-CN",
21
+ "en|zh-TW", "en|nl", "en|fr", "en|de", "en|el", "en|it", "en|ja", "en|ko",
22
+ "en|pt", "en|ru", "en|es", "en|sv", "fr|en", "fr|de", "fr|sv", "de|en", "de|fr", "de|sv", "el|en",
23
+ "it|en", "ja|en", "ko|en", "pt|en", "ru|en", "es|en", "es|sv", "nl|sv",
24
+ "sv|de", "sv|en", "sv|es", "sv|fr", "sv|nl"
25
+ ]
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ module Translate
2
+ class UnsupportedLanguagePair < StandardError
3
+ end
4
+
5
+ class RSay
6
+ class << self
7
+ def translate(text, from, to)
8
+ if Language::AVAILABLE_PAIR.include?("#{from}|#{to}")
9
+
10
+ @uri = URI.parse("http://ajax.googleapis.com/ajax/services/language/translate")
11
+
12
+ string = "#{@uri.path}?" +
13
+ { :langpair => "#{from}|#{to}", :q => text, :v => 1.0 }.map { |k,v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&')
14
+
15
+ coder = HTMLEntities.new
16
+ coder.decode(JSON.parse(Net::HTTP.get(@uri.host, string))['responseData']['translatedText'])
17
+ else
18
+ raise UnsupportedLanguagePair, "Translation from '#{from}' to '#{to}' isn't supported yet!"
19
+ end
20
+ end
21
+
22
+ alias_method :t, :translate
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rsay
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - MEKDIGITAL
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-05 00:00:00 -08:00
13
+ default_executable: bin/rsay
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
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.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: htmlentities
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.0
34
+ version:
35
+ description: RSay is yet another google translate api ruby interface.
36
+ email: etozzato@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - README
45
+ - MIT-LICENSE
46
+ - lib/rsay.rb
47
+ - lib/rsay/rsay.rb
48
+ - lib/rsay/language.rb
49
+ - bin/rsay
50
+ has_rdoc: false
51
+ homepage: http://code.google.com/p/rsay/
52
+ post_install_message:
53
+ rdoc_options: []
54
+
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ requirements: []
70
+
71
+ rubyforge_project:
72
+ rubygems_version: 1.2.0
73
+ signing_key:
74
+ specification_version: 2
75
+ summary: RSay is yet another google translate api ruby interface.
76
+ test_files: []
77
+