exvo_globalize 0.2.0 → 0.2.1
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.md +17 -0
- data/exvo_globalize.gemspec +2 -0
- data/lib/exvo_globalize/backend/chain.rb +12 -0
- data/lib/exvo_globalize/backend/flatten.rb +24 -0
- data/lib/exvo_globalize/version.rb +1 -1
- data/lib/exvo_globalize.rb +3 -0
- data/lib/tasks/dump.rake +17 -0
- data/spec/exvo_globalize/fallback_spec.rb +1 -2
- data/spec/exvo_globalize/flatten_spec.rb +43 -0
- data/spec/exvo_globalize/globalize_store_spec.rb +1 -2
- metadata +57 -23
data/README.md
CHANGED
@@ -49,6 +49,23 @@ I18n::Backend::GlobalizeStore.authenticator = proc {
|
|
49
49
|
`authenticate_user!` and `require_admin!` are just exemplary authorization actions.
|
50
50
|
|
51
51
|
|
52
|
+
|
53
|
+
## Getting back your database stored translations
|
54
|
+
|
55
|
+
If you wish to extract your database stored translations to a separate YAML/Ruby file, there are two rake task to help you with that:
|
56
|
+
|
57
|
+
```bash
|
58
|
+
$ bundle exec rake globalize:translations:dump:yaml
|
59
|
+
```
|
60
|
+
|
61
|
+
and
|
62
|
+
|
63
|
+
```bash
|
64
|
+
$ bundle exec rake globalize:translations:dump:ruby
|
65
|
+
```
|
66
|
+
|
67
|
+
|
68
|
+
|
52
69
|
## Globalize integration
|
53
70
|
|
54
71
|
In order to fully integrate this gem with Globalize, after installing it you need to register your application (http://globalize.exvo.com/) and order some translations (Globalize should automatically detect the gem installation and should let you choose the JSON translations option).
|
data/exvo_globalize.gemspec
CHANGED
@@ -22,6 +22,8 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.add_dependency 'rails', ['>= 3.0.0']
|
23
23
|
s.add_dependency 'i18n', ['~> 0.5.0']
|
24
24
|
s.add_dependency 'haml', ['>= 3.0.0']
|
25
|
+
s.add_dependency 'awesome_print', ['>= 0.3.2']
|
26
|
+
s.add_dependency 'ya2yaml', ['>= 0.30']
|
25
27
|
s.add_dependency 'httparty', ['>= 0.6.1']
|
26
28
|
s.add_development_dependency 'guard', ['>= 0.5.0']
|
27
29
|
s.add_development_dependency 'guard-rspec', ['>= 0.4.0']
|
@@ -30,6 +30,18 @@ module I18n
|
|
30
30
|
return backend.send(:store_flatten_translation, *args) if backend.respond_to?(:store_flatten_translation)
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
34
|
+
# convinience methods to quickly access a chosen backend
|
35
|
+
|
36
|
+
# I18n.backend.simple
|
37
|
+
def simple
|
38
|
+
backends.detect { |backend| backend.is_a?(I18n::Backend::Simple) }
|
39
|
+
end
|
40
|
+
|
41
|
+
# I18n.backend.globalize_store
|
42
|
+
def globalize_store
|
43
|
+
backends.detect { |backend| backend.is_a?(I18n::Backend::GlobalizeStore) }
|
44
|
+
end
|
33
45
|
end
|
34
46
|
|
35
47
|
include Implementation
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module I18n
|
2
|
+
module Backend
|
3
|
+
module Flatten
|
4
|
+
|
5
|
+
# Nest keys for flatten (dotted) hashes
|
6
|
+
# IN: { "hello.world" => "hello world" }
|
7
|
+
# OUT: { :hello => { :world => "hello world" } }
|
8
|
+
def nest_translations(hash)
|
9
|
+
hash.map do |main_key, main_value|
|
10
|
+
main_key.to_s.split(".").reverse.inject(main_value) do |value, key|
|
11
|
+
if value.is_a?(Hash)
|
12
|
+
{ key.to_s => nest_translations(value) }
|
13
|
+
else
|
14
|
+
{ key.to_s => value }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end.inject(&:deep_merge)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
include Flatten
|
23
|
+
end
|
24
|
+
end
|
data/lib/exvo_globalize.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
require "exvo_globalize/version"
|
2
2
|
require "exvo_globalize/backend/chain"
|
3
3
|
require "exvo_globalize/backend/fallback"
|
4
|
+
require 'exvo_globalize/backend/flatten'
|
4
5
|
require "exvo_globalize/backend/globalize_store"
|
5
6
|
require "exvo_globalize/backend/simple"
|
6
7
|
require 'exvo_globalize/globalize_app'
|
7
8
|
require 'haml'
|
8
9
|
require 'httparty'
|
10
|
+
require 'awesome_print'
|
11
|
+
require 'ya2yaml'
|
9
12
|
|
10
13
|
# Make it a Rails engine
|
11
14
|
module ExvoGlobalize
|
data/lib/tasks/dump.rake
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
namespace :"globalize:translations:dump" do
|
2
|
+
desc "Dump GlobalizeStore I18n translations as YAML"
|
3
|
+
task :yaml => :environment do
|
4
|
+
puts "Dumping translations as YAML..."
|
5
|
+
backend = I18n.backend.globalize_store
|
6
|
+
translations = backend.available_translations
|
7
|
+
puts backend.nest_translations(translations).ya2yaml
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Dump GlobalizeStore I18n translations as Ruby Hash"
|
11
|
+
task :ruby => :environment do
|
12
|
+
puts "Dumping translations as Ruby Hash..."
|
13
|
+
backend = I18n.backend.globalize_store
|
14
|
+
translations = backend.available_translations
|
15
|
+
ap backend.nest_translations(translations), { :plain => true, :indent => 2, :sorted_hash_keys => true }
|
16
|
+
end
|
17
|
+
end
|
@@ -17,8 +17,7 @@ describe ExvoGlobalize do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "uses translation from the Simple backend if it is not found in the GlobalizeTranslation backend" do
|
20
|
-
|
21
|
-
simple_backend.translate(I18n.default_locale, :name).should eql(I18n.translate(:name))
|
20
|
+
I18n.backend.simple.translate(I18n.default_locale, :name).should eql(I18n.translate(:name))
|
22
21
|
end
|
23
22
|
|
24
23
|
after { I18n.locale = I18n.default_locale }
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ExvoGlobalize do
|
4
|
+
|
5
|
+
let(:backend) { I18n.backend.globalize_store }
|
6
|
+
|
7
|
+
it "should not change a normal hash" do
|
8
|
+
hash = { 'hello' => "Hello", 'world' => "World" }
|
9
|
+
backend.nest_translations(hash).should eq(hash)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should not change a nested hash" do
|
13
|
+
nested_hash = { 'en' => { 'hello' => "Hello World!", 'world' => "World!" } }
|
14
|
+
backend.nest_translations(nested_hash).should eq(nested_hash)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should nest a simple flatten hash" do
|
18
|
+
hash = { "hello.world" => "Hello World!" }
|
19
|
+
nested_hash = { 'hello' => { 'world' => "Hello World!" } }
|
20
|
+
backend.nest_translations(hash).should eq(nested_hash)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should nest a complicated flatten hash with symbol key" do
|
24
|
+
hash = {
|
25
|
+
:en => {
|
26
|
+
"hello.world" => "Hello World!",
|
27
|
+
"hello.earth" => "Hello Earth!"
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
nested_hash = {
|
32
|
+
'en' => {
|
33
|
+
'hello' => {
|
34
|
+
'world' => "Hello World!",
|
35
|
+
'earth' => "Hello Earth!"
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
backend.nest_translations(hash).should eq(nested_hash)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -48,8 +48,7 @@ describe ExvoGlobalize do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
it "lists available_translations from the Simple backend (YAML files)" do
|
51
|
-
|
52
|
-
simple_backend.available_translations[:en][:title].should eq('YAML Title')
|
51
|
+
I18n.backend.simple.available_translations[:en][:title].should eq('YAML Title')
|
53
52
|
end
|
54
53
|
|
55
54
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exvo_globalize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Pawe\xC5\x82 Go\xC5\x9Bcicki"
|
@@ -67,9 +67,40 @@ dependencies:
|
|
67
67
|
type: :runtime
|
68
68
|
version_requirements: *id003
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: awesome_print
|
71
71
|
prerelease: false
|
72
72
|
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 23
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
- 3
|
81
|
+
- 2
|
82
|
+
version: 0.3.2
|
83
|
+
type: :runtime
|
84
|
+
version_requirements: *id004
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: ya2yaml
|
87
|
+
prerelease: false
|
88
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 55
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
- 30
|
97
|
+
version: "0.30"
|
98
|
+
type: :runtime
|
99
|
+
version_requirements: *id005
|
100
|
+
- !ruby/object:Gem::Dependency
|
101
|
+
name: httparty
|
102
|
+
prerelease: false
|
103
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
73
104
|
none: false
|
74
105
|
requirements:
|
75
106
|
- - ">="
|
@@ -81,11 +112,11 @@ dependencies:
|
|
81
112
|
- 1
|
82
113
|
version: 0.6.1
|
83
114
|
type: :runtime
|
84
|
-
version_requirements: *
|
115
|
+
version_requirements: *id006
|
85
116
|
- !ruby/object:Gem::Dependency
|
86
117
|
name: guard
|
87
118
|
prerelease: false
|
88
|
-
requirement: &
|
119
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
89
120
|
none: false
|
90
121
|
requirements:
|
91
122
|
- - ">="
|
@@ -97,11 +128,11 @@ dependencies:
|
|
97
128
|
- 0
|
98
129
|
version: 0.5.0
|
99
130
|
type: :development
|
100
|
-
version_requirements: *
|
131
|
+
version_requirements: *id007
|
101
132
|
- !ruby/object:Gem::Dependency
|
102
133
|
name: guard-rspec
|
103
134
|
prerelease: false
|
104
|
-
requirement: &
|
135
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
105
136
|
none: false
|
106
137
|
requirements:
|
107
138
|
- - ">="
|
@@ -113,11 +144,11 @@ dependencies:
|
|
113
144
|
- 0
|
114
145
|
version: 0.4.0
|
115
146
|
type: :development
|
116
|
-
version_requirements: *
|
147
|
+
version_requirements: *id008
|
117
148
|
- !ruby/object:Gem::Dependency
|
118
149
|
name: sqlite3
|
119
150
|
prerelease: false
|
120
|
-
requirement: &
|
151
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
121
152
|
none: false
|
122
153
|
requirements:
|
123
154
|
- - ">="
|
@@ -128,11 +159,11 @@ dependencies:
|
|
128
159
|
- 3
|
129
160
|
version: "1.3"
|
130
161
|
type: :development
|
131
|
-
version_requirements: *
|
162
|
+
version_requirements: *id009
|
132
163
|
- !ruby/object:Gem::Dependency
|
133
164
|
name: rspec
|
134
165
|
prerelease: false
|
135
|
-
requirement: &
|
166
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
136
167
|
none: false
|
137
168
|
requirements:
|
138
169
|
- - ">="
|
@@ -143,11 +174,11 @@ dependencies:
|
|
143
174
|
- 6
|
144
175
|
version: "2.6"
|
145
176
|
type: :development
|
146
|
-
version_requirements: *
|
177
|
+
version_requirements: *id010
|
147
178
|
- !ruby/object:Gem::Dependency
|
148
179
|
name: rspec-rails
|
149
180
|
prerelease: false
|
150
|
-
requirement: &
|
181
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
151
182
|
none: false
|
152
183
|
requirements:
|
153
184
|
- - ">="
|
@@ -158,11 +189,11 @@ dependencies:
|
|
158
189
|
- 6
|
159
190
|
version: "2.6"
|
160
191
|
type: :development
|
161
|
-
version_requirements: *
|
192
|
+
version_requirements: *id011
|
162
193
|
- !ruby/object:Gem::Dependency
|
163
194
|
name: factory_girl_rails
|
164
195
|
prerelease: false
|
165
|
-
requirement: &
|
196
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
166
197
|
none: false
|
167
198
|
requirements:
|
168
199
|
- - ">="
|
@@ -174,11 +205,11 @@ dependencies:
|
|
174
205
|
- 0
|
175
206
|
version: 1.1.0
|
176
207
|
type: :development
|
177
|
-
version_requirements: *
|
208
|
+
version_requirements: *id012
|
178
209
|
- !ruby/object:Gem::Dependency
|
179
210
|
name: shoulda-matchers
|
180
211
|
prerelease: false
|
181
|
-
requirement: &
|
212
|
+
requirement: &id013 !ruby/object:Gem::Requirement
|
182
213
|
none: false
|
183
214
|
requirements:
|
184
215
|
- - ">="
|
@@ -192,11 +223,11 @@ dependencies:
|
|
192
223
|
- 3
|
193
224
|
version: 1.0.0.beta3
|
194
225
|
type: :development
|
195
|
-
version_requirements: *
|
226
|
+
version_requirements: *id013
|
196
227
|
- !ruby/object:Gem::Dependency
|
197
228
|
name: capybara
|
198
229
|
prerelease: false
|
199
|
-
requirement: &
|
230
|
+
requirement: &id014 !ruby/object:Gem::Requirement
|
200
231
|
none: false
|
201
232
|
requirements:
|
202
233
|
- - ">="
|
@@ -208,11 +239,11 @@ dependencies:
|
|
208
239
|
- 0
|
209
240
|
version: 1.0.0
|
210
241
|
type: :development
|
211
|
-
version_requirements: *
|
242
|
+
version_requirements: *id014
|
212
243
|
- !ruby/object:Gem::Dependency
|
213
244
|
name: json
|
214
245
|
prerelease: false
|
215
|
-
requirement: &
|
246
|
+
requirement: &id015 !ruby/object:Gem::Requirement
|
216
247
|
none: false
|
217
248
|
requirements:
|
218
249
|
- - ">="
|
@@ -224,7 +255,7 @@ dependencies:
|
|
224
255
|
- 1
|
225
256
|
version: 1.5.1
|
226
257
|
type: :development
|
227
|
-
version_requirements: *
|
258
|
+
version_requirements: *id015
|
228
259
|
description: It exposes `/globalize/translations.json` with JSON of all translations in the app
|
229
260
|
email:
|
230
261
|
- pawel.goscicki@gmail.com
|
@@ -252,6 +283,7 @@ files:
|
|
252
283
|
- lib/exvo_globalize.rb
|
253
284
|
- lib/exvo_globalize/backend/chain.rb
|
254
285
|
- lib/exvo_globalize/backend/fallback.rb
|
286
|
+
- lib/exvo_globalize/backend/flatten.rb
|
255
287
|
- lib/exvo_globalize/backend/globalize_store.rb
|
256
288
|
- lib/exvo_globalize/backend/simple.rb
|
257
289
|
- lib/exvo_globalize/engine.rb
|
@@ -259,10 +291,12 @@ files:
|
|
259
291
|
- lib/exvo_globalize/version.rb
|
260
292
|
- lib/generators/exvo_globalize/exvo_globalize_generator.rb
|
261
293
|
- lib/generators/exvo_globalize/templates/migration.rb
|
294
|
+
- lib/tasks/dump.rake
|
262
295
|
- spec/app.rb
|
263
296
|
- spec/controllers/globalize_translations_controller_spec.rb
|
264
297
|
- spec/exvo_globalize/caching_spec.rb
|
265
298
|
- spec/exvo_globalize/fallback_spec.rb
|
299
|
+
- spec/exvo_globalize/flatten_spec.rb
|
266
300
|
- spec/exvo_globalize/globalize_store_spec.rb
|
267
301
|
- spec/exvo_globalize/pluralizations_spec.rb
|
268
302
|
- spec/factories.rb
|