goobalize3 0.0.2 → 0.1.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.
- data/README.rdoc +8 -7
- data/lib/goobalize3/version.rb +1 -1
- data/lib/google_translate.rb +10 -0
- metadata +5 -9
data/README.rdoc
CHANGED
@@ -5,19 +5,20 @@ Goobalize3 (Google + Globalize3) is useful to auto translate the attributes of y
|
|
5
5
|
If you have a model with some attributes translated with {Globalize3}[https://github.com/svenfuchs/globalize3] you
|
6
6
|
can in easy way auto translate them via {Google Translate}[http://translate.google.com].
|
7
7
|
|
8
|
-
==
|
8
|
+
== Requirements
|
9
9
|
|
10
|
-
|
10
|
+
* Globalize3
|
11
11
|
|
12
|
-
|
12
|
+
== Installation
|
13
13
|
|
14
|
-
As
|
14
|
+
* As gem: put <tt>gem 'goobalize3'</tt> in your Gemfile
|
15
|
+
* As plugin: run <tt>rails plugin install git@github.com:pioz/goobalize3.git</tt>
|
15
16
|
|
16
|
-
|
17
|
+
Now create <tt>google_translate.yml</tt> file in your rails config folder and put the follow line:
|
17
18
|
|
18
|
-
|
19
|
+
api : YOUR_GOOGLE_TRANSLATE_API_KEY
|
19
20
|
|
20
|
-
|
21
|
+
You can get api key at {Google apis console page}[https://code.google.com/apis/console/].
|
21
22
|
|
22
23
|
== Usage
|
23
24
|
|
data/lib/goobalize3/version.rb
CHANGED
data/lib/google_translate.rb
CHANGED
@@ -5,6 +5,9 @@ module GoogleTranslate
|
|
5
5
|
HOST = 'www.googleapis.com'
|
6
6
|
SERVICE = '/language/translate/v2'
|
7
7
|
QUERY_LIMIT = 5000
|
8
|
+
LOCALES_MAP = {
|
9
|
+
:cn => :'zh-CN'
|
10
|
+
}
|
8
11
|
|
9
12
|
def self.get_api
|
10
13
|
config_file = "#{Rails.root}/config/google_translate.yml"
|
@@ -19,9 +22,16 @@ module GoogleTranslate
|
|
19
22
|
return nil
|
20
23
|
end
|
21
24
|
|
25
|
+
def self.map(locale)
|
26
|
+
mapped = LOCALES_MAP[locale]
|
27
|
+
mapped.nil? ? locale : mapped
|
28
|
+
end
|
29
|
+
|
22
30
|
def self.perform(params)
|
23
31
|
@@goole_translate_api ||= get_api
|
24
32
|
params[:q] = CGI::escape(params[:q].to_s[0..QUERY_LIMIT])
|
33
|
+
params[:source] = map params[:source]
|
34
|
+
params[:target] = map params[:target]
|
25
35
|
params.merge!(:key => @@goole_translate_api, :format => 'html')
|
26
36
|
data = []
|
27
37
|
params.each_pair { |k,v| data << "#{k}=#{v}" }
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: goobalize3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
4
|
+
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
7
|
+
- 1
|
8
8
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.2
|
9
|
+
version: 0.1.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Enrico Pilotto
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2011-01
|
17
|
+
date: 2011-03-01 00:00:00 +01:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
28
|
segments:
|
31
29
|
- 0
|
32
30
|
version: "0"
|
@@ -65,7 +63,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
63
|
requirements:
|
66
64
|
- - ">="
|
67
65
|
- !ruby/object:Gem::Version
|
68
|
-
hash: 3
|
69
66
|
segments:
|
70
67
|
- 0
|
71
68
|
version: "0"
|
@@ -74,14 +71,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
71
|
requirements:
|
75
72
|
- - ">="
|
76
73
|
- !ruby/object:Gem::Version
|
77
|
-
hash: 3
|
78
74
|
segments:
|
79
75
|
- 0
|
80
76
|
version: "0"
|
81
77
|
requirements: []
|
82
78
|
|
83
79
|
rubyforge_project: goobalize3
|
84
|
-
rubygems_version: 1.
|
80
|
+
rubygems_version: 1.3.7
|
85
81
|
signing_key:
|
86
82
|
specification_version: 3
|
87
83
|
summary: Auto translate with Google Translate the Globalize3 attributes
|