to_lang 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +19 -0
- data/README.textile +7 -10
- data/lib/to_lang.rb +2 -0
- data/lib/to_lang/codemap.rb +1 -1
- data/lib/to_lang/string_methods.rb +15 -24
- data/lib/to_lang/version.rb +1 -1
- metadata +4 -3
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (C) 2010-2011 by Jimmy Cuadra
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.textile
CHANGED
@@ -54,19 +54,20 @@ Using @String#translate@ directly:
|
|
54
54
|
|
55
55
|
h2. Debugging
|
56
56
|
|
57
|
-
@String#translate@ also has the advantage of allowing you to get debug output for a translation. @String#translate@ accepts a @:debug@ option with three possible values: @:request@, @:response@, and @:all@. @:request@ will cause the method to return the
|
57
|
+
@String#translate@ also has the advantage of allowing you to get debug output for a translation. @String#translate@ accepts a @:debug@ option with three possible values: @:request@, @:response@, and @:all@. @:request@ will cause the method to return a hash of the parameters that will be sent to the Google Translate API. @:response@ will cause the method to return the full response from the API call as a hash. @:all@ will cause the method to return a hash which contains both the request hash and the full response.
|
58
58
|
|
59
|
-
<pre><code>"hello world".translate('es', :debug => :
|
60
|
-
=>
|
59
|
+
<pre><code>"hello world".translate('es', :debug => :request)
|
60
|
+
=> {:key=>"my_key", :q=>"hello world", :target=>"es"}
|
61
61
|
</code></pre>
|
62
62
|
|
63
63
|
<pre><code>"hello world".translate('es', :debug => :response)
|
64
|
-
=> {"data"=>{"translations"=>[{"translatedText"=>"hola mundo"}]}}
|
64
|
+
=> {"data"=>{"translations"=>[{"translatedText"=>"hola mundo", "detectedSourceLanguage"=>"en"}]}}
|
65
65
|
</code></pre>
|
66
66
|
|
67
67
|
<pre><code>"hello world".translate('es', :debug => :all)
|
68
|
-
=> {:request=>"
|
69
|
-
:response=>{"data"=>{"translations"=>[{"translatedText"=>"hola mundo"
|
68
|
+
=> {:request=>{:key=>"my_key", :q=>"hello world", :target=>"es"},
|
69
|
+
:response=>{"data"=>{"translations"=>[{"translatedText"=>"hola mundo",
|
70
|
+
"detectedSourceLanguage"=>"en"}]}}}
|
70
71
|
</code></pre>
|
71
72
|
|
72
73
|
h2. Supported Languages
|
@@ -130,10 +131,6 @@ h2. Documentation
|
|
130
131
|
|
131
132
|
API documentation can be found at "rubydoc.info":http://rubydoc.info/github/jimmycuadra/to_lang/master/frames.
|
132
133
|
|
133
|
-
h2. Roadmap
|
134
|
-
|
135
|
-
* Investigate Unicode support for Ruby 1.8. *to_lang* has only been tested with 1.9.
|
136
|
-
|
137
134
|
h2. Feedback and Contributions
|
138
135
|
|
139
136
|
Feedback is greatly appreciated. If you have any problems with *to_lang*, please open a new issue. Make sure you are using the latest version of the gem, or HEAD if you've cloned the Git repository directly. Please include debugging output from using @String#translate@'s @:debug@ option, if relevant to your issue. If you'd like to fix bugs, add features, or improve the library in general, feel free to fork the project and send me a pull request with your changes.
|
data/lib/to_lang.rb
CHANGED
data/lib/to_lang/codemap.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module ToLang
|
2
|
-
# A list of all the languages {ToLang} supports and the language code each maps to. Strings will gain @to_language@ and @
|
2
|
+
# A list of all the languages {ToLang} supports and the language code each maps to. Strings will gain @to_language@, @to_language_from_language@, and @from_language_to_language@ methods for any @language@ in this list.
|
3
3
|
#
|
4
4
|
CODEMAP = {
|
5
5
|
'afrikaans' => 'af',
|
@@ -28,37 +28,19 @@ module ToLang
|
|
28
28
|
case method.to_s
|
29
29
|
when /^to_(.*)_from_(.*)$/
|
30
30
|
if CODEMAP[$1] && CODEMAP[$2]
|
31
|
-
|
32
|
-
|
33
|
-
self.class.send(:define_method, new_method_name) do
|
34
|
-
translate(CODEMAP[$1], :from => CODEMAP[$2])
|
35
|
-
end
|
36
|
-
|
37
|
-
return send(new_method_name)
|
31
|
+
define_and_call_method(method) { translate(CODEMAP[$1], :from => CODEMAP[$2]) }
|
38
32
|
else
|
39
33
|
original_method_missing(method, *args, &block)
|
40
34
|
end
|
41
35
|
when /^from_(.*)_to_(.*)$/
|
42
36
|
if CODEMAP[$1] && CODEMAP[$2]
|
43
|
-
|
44
|
-
|
45
|
-
self.class.send(:define_method, new_method_name) do
|
46
|
-
translate(CODEMAP[$2], :from => CODEMAP[$1])
|
47
|
-
end
|
48
|
-
|
49
|
-
return send(new_method_name)
|
37
|
+
define_and_call_method(method) { translate(CODEMAP[$2], :from => CODEMAP[$1]) }
|
50
38
|
else
|
51
39
|
original_method_missing(method, *args, &block)
|
52
40
|
end
|
53
41
|
when /^to_(.*)$/
|
54
42
|
if CODEMAP[$1]
|
55
|
-
|
56
|
-
|
57
|
-
self.class.send(:define_method, new_method_name) do
|
58
|
-
translate(CODEMAP[$1])
|
59
|
-
end
|
60
|
-
|
61
|
-
return send(new_method_name)
|
43
|
+
define_and_call_method(method) { translate(CODEMAP[$1]) }
|
62
44
|
else
|
63
45
|
original_method_missing(method, *args, &block)
|
64
46
|
end
|
@@ -76,9 +58,7 @@ module ToLang
|
|
76
58
|
#
|
77
59
|
def respond_to?(method, include_private = false)
|
78
60
|
case method.to_s
|
79
|
-
when /^to_(.*)_from_(.*)$/
|
80
|
-
return true if CODEMAP[$1] && CODEMAP[$2]
|
81
|
-
when /^from_(.*)_to_(.*)$/
|
61
|
+
when /^to_(.*)_from_(.*)$/, /^from_(.*)_to_(.*)$/
|
82
62
|
return true if CODEMAP[$1] && CODEMAP[$2]
|
83
63
|
when /^to_(.*)$/
|
84
64
|
return true if CODEMAP[$1]
|
@@ -86,5 +66,16 @@ module ToLang
|
|
86
66
|
|
87
67
|
original_respond_to?(method, include_private)
|
88
68
|
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
# Defines a method dynamically and then calls it.
|
73
|
+
#
|
74
|
+
# @private
|
75
|
+
#
|
76
|
+
def define_and_call_method(method, &block)
|
77
|
+
self.class.send(:define_method, method, block)
|
78
|
+
send method
|
79
|
+
end
|
89
80
|
end
|
90
81
|
end
|
data/lib/to_lang/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jimmy Cuadra
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-01-
|
17
|
+
date: 2011-01-13 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- .gitignore
|
129
129
|
- .yardopts
|
130
130
|
- Gemfile
|
131
|
+
- LICENSE
|
131
132
|
- README.textile
|
132
133
|
- Rakefile
|
133
134
|
- lib/to_lang.rb
|