exvo_globalize 0.3.0 → 0.3.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/app/controllers/globalize_translations_controller.rb +1 -1
- data/lib/exvo_globalize/backend/chain.rb +14 -3
- data/lib/exvo_globalize/version.rb +1 -1
- data/spec/controllers/globalize_translations_controller_spec.rb +2 -2
- data/spec/exvo_globalize/globalize_store_spec.rb +14 -4
- data/spec/fixtures/locales/en.yml +1 -1
- metadata +4 -4
@@ -14,7 +14,7 @@ class GlobalizeTranslationsController < ApplicationController
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def update
|
17
|
-
if I18n.backend.
|
17
|
+
if I18n.backend.store_nested_translations(@globalize_app.fetch_translations)
|
18
18
|
flash.now[:notice] = 'Translations updated'
|
19
19
|
else
|
20
20
|
flash.now[:alert] = 'There was a problem while updating translations'
|
@@ -7,7 +7,7 @@ module I18n
|
|
7
7
|
# returning a combined hash with translations from all chained backends
|
8
8
|
def available_translations
|
9
9
|
# reverse, so that the translations from the first backend (GlobalizeStore) overwrite/overshadow others
|
10
|
-
backends.map { |backend| backend.available_translations }.reverse.inject(&:merge)
|
10
|
+
@available_translations ||= backends.map { |backend| backend.available_translations }.reverse.inject(&:merge)
|
11
11
|
end
|
12
12
|
|
13
13
|
# Return a hash only with Application translations
|
@@ -30,11 +30,22 @@ module I18n
|
|
30
30
|
translations
|
31
31
|
end
|
32
32
|
|
33
|
-
# stores a whole Hash of
|
33
|
+
# stores a whole Hash of nested translations (like those: { :en => { :session => { :title => 'Title' } } })
|
34
|
+
def store_nested_translations(translations_hash)
|
35
|
+
return false if translations_hash.blank?
|
36
|
+
|
37
|
+
translations_hash.reject { |locale, translations| locale.to_sym == :default_locale }.each do |locale, translations|
|
38
|
+
next if translations.blank?
|
39
|
+
|
40
|
+
store_translations(locale, translations)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# stores a whole Hash of flattened translations (like those: { :en => { 'session.title' => 'Title' } })
|
34
45
|
def store_flatten_translations(translations_hash)
|
35
46
|
return false if translations_hash.blank?
|
36
47
|
|
37
|
-
translations_hash.reject { |
|
48
|
+
translations_hash.reject { |locale, translations| locale.to_sym == :default_locale }.each do |locale, translations|
|
38
49
|
next if translations.blank?
|
39
50
|
|
40
51
|
translations.each do |key, value|
|
@@ -56,7 +56,7 @@ describe GlobalizeTranslationsController do
|
|
56
56
|
|
57
57
|
describe "PUT :update" do
|
58
58
|
let(:intro) { "Introduction" }
|
59
|
-
let(:translations) { { :en => { :intro => intro } } }
|
59
|
+
let(:translations) { { :en => { :intro => { :title => intro } } } }
|
60
60
|
|
61
61
|
before do
|
62
62
|
controller.stub!(:require_admin).and_return(true)
|
@@ -65,7 +65,7 @@ describe GlobalizeTranslationsController do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
it "updates the translations" do
|
68
|
-
I18n.t(:intro).should eq(intro)
|
68
|
+
I18n.t(:title, :scope => :intro).should eq(intro)
|
69
69
|
end
|
70
70
|
|
71
71
|
it "sets a flash notice" do
|
@@ -21,6 +21,7 @@ describe ExvoGlobalize do
|
|
21
21
|
context "translation storage" do
|
22
22
|
let(:hello_world) { 'Hello world' }
|
23
23
|
let(:hello_earth) { 'Hello Earth' }
|
24
|
+
let(:hello_mars) { 'Hello Mars' }
|
24
25
|
|
25
26
|
it "stores a flatten translations hash" do
|
26
27
|
I18n.backend.store_flatten_translations({ :en => { 'hello.world' => hello_world, 'hello.earth' => hello_earth } })
|
@@ -29,8 +30,13 @@ describe ExvoGlobalize do
|
|
29
30
|
end
|
30
31
|
|
31
32
|
it "stores a flatten translation" do
|
32
|
-
I18n.backend.store_flatten_translation(I18n.locale, 'hello.
|
33
|
-
I18n.translate(:
|
33
|
+
I18n.backend.store_flatten_translation(I18n.locale, 'hello.mars', hello_mars)
|
34
|
+
I18n.translate(:mars, :scope => [:hello]).should eql(hello_mars)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "stores a nested translations hash" do
|
38
|
+
I18n.backend.store_nested_translations({ :en => { :nested => { :hello => hello_world } } })
|
39
|
+
I18n.translate(:hello, :scope => :nested).should eql(hello_world)
|
34
40
|
end
|
35
41
|
|
36
42
|
it "stores a nested translation" do
|
@@ -40,7 +46,7 @@ describe ExvoGlobalize do
|
|
40
46
|
end
|
41
47
|
|
42
48
|
it "falls back to the YAML file if the translation is missing in the GlobalizeStore backend (db)" do
|
43
|
-
I18n.translate('yaml.title').should eq('YAML Title')
|
49
|
+
I18n.translate('yaml.title').should eq('YAML Nested Title')
|
44
50
|
end
|
45
51
|
|
46
52
|
it "prioritizes the translations from GlobalizeStore backend (db) over others" do
|
@@ -48,7 +54,11 @@ describe ExvoGlobalize do
|
|
48
54
|
end
|
49
55
|
|
50
56
|
it "lists available_translations from the Simple backend (YAML files)" do
|
51
|
-
I18n.backend.simple.available_translations[:en][:title].should eq('YAML Title')
|
57
|
+
I18n.backend.simple.available_translations[:en][:yaml][:title].should eq('YAML Nested Title')
|
58
|
+
end
|
59
|
+
|
60
|
+
it "lists available app translations" do
|
61
|
+
I18n.backend.available_app_translations[:en][:helpers][:select].has_key?(:prompt).should be_true
|
52
62
|
end
|
53
63
|
|
54
64
|
it "excludes fixtures from app_translations and does so without breaking the I18n.load_path" do
|
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: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Pawe\xC5\x82 Go\xC5\x9Bcicki"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-08-
|
18
|
+
date: 2011-08-29 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|