refinerycms-i18n 0.9.9.10 → 0.9.9.12
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gemspec.rb +1 -1
- data/lib/refinery/i18n.rb +44 -67
- metadata +3 -3
data/lib/gemspec.rb
CHANGED
data/lib/refinery/i18n.rb
CHANGED
@@ -25,51 +25,58 @@ module Refinery
|
|
25
25
|
::Refinery::I18n.enabled? ? { :locale => ::I18n.locale } : {}
|
26
26
|
end
|
27
27
|
|
28
|
-
prepend_before_filter :find_or_set_locale
|
29
|
-
|
30
28
|
def find_or_set_locale
|
31
29
|
if ::Refinery::I18n.enabled?
|
32
30
|
if ::Refinery::I18n.has_locale?(locale = params[:locale].try(:to_sym))
|
33
|
-
|
31
|
+
::I18n.locale = locale
|
34
32
|
elsif locale.present? and locale != ::Refinery::I18n.default_frontend_locale
|
35
|
-
|
33
|
+
params[:locale] = ::I18n.locale = ::Refinery::I18n.default_frontend_locale
|
36
34
|
redirect_to(params, :notice => "The locale '#{locale}' is not supported.") and return
|
37
35
|
else
|
38
|
-
|
36
|
+
::I18n.locale = ::Refinery::I18n.default_frontend_locale
|
39
37
|
end
|
38
|
+
|
39
|
+
Thread.current[:globalize_locale] = ::I18n.locale
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
+
prepend_before_filter :find_or_set_locale
|
43
44
|
protected :default_url_options, :find_or_set_locale
|
44
45
|
end
|
45
46
|
|
46
47
|
::Admin::BaseController.class_eval do
|
47
|
-
# globalize! should be prepended first so that it runs after find_or_set_locale
|
48
|
-
prepend_before_filter :globalize!, :find_or_set_locale
|
49
|
-
|
50
48
|
def find_or_set_locale
|
51
|
-
if (params[:set_locale]
|
49
|
+
if (params[:set_locale] and ::Refinery::I18n.locales.keys.map(&:to_sym).include?(params[:set_locale].to_sym))
|
52
50
|
::Refinery::I18n.current_locale = params[:set_locale].to_sym
|
53
|
-
redirect_back_or_default(
|
51
|
+
redirect_back_or_default(admin_root_path) and return
|
54
52
|
else
|
55
53
|
::I18n.locale = ::Refinery::I18n.current_locale
|
56
54
|
end
|
57
55
|
end
|
58
56
|
|
59
57
|
def globalize!
|
60
|
-
|
61
|
-
|
58
|
+
if ::Refinery::I18n.frontend_locales.any?
|
59
|
+
if params[:switch_locale]
|
60
|
+
Thread.current[:globalize_locale] = params[:switch_locale].to_sym
|
61
|
+
elsif ::I18n.locale != ::Refinery::I18n.default_frontend_locale
|
62
|
+
Thread.current[:globalize_locale] = ::Refinery::I18n.default_frontend_locale
|
63
|
+
end
|
64
|
+
end
|
62
65
|
|
63
|
-
|
66
|
+
Thread.current[:globalize_locale] = ::I18n.locale if Thread.current[:globalize_locale].nil?
|
67
|
+
end
|
68
|
+
# globalize! should be prepended first so that it runs after find_or_set_locale
|
69
|
+
prepend_before_filter :globalize!, :find_or_set_locale
|
70
|
+
protected :globalize!, :find_or_set_locale
|
64
71
|
end
|
65
72
|
end
|
66
73
|
|
67
74
|
config.after_initialize do
|
68
|
-
::Refinery::I18n.setup!
|
75
|
+
::Refinery::I18n.setup!
|
69
76
|
|
70
77
|
Refinery::Plugin.register do |plugin|
|
71
78
|
plugin.name = "refinery_i18n"
|
72
|
-
plugin.version = %q{0.9.9.
|
79
|
+
plugin.version = %q{0.9.9.11}
|
73
80
|
plugin.hide_from_menu = true
|
74
81
|
plugin.always_allow_access = true
|
75
82
|
end
|
@@ -79,38 +86,29 @@ module Refinery
|
|
79
86
|
|
80
87
|
class << self
|
81
88
|
|
82
|
-
attr_accessor :built_in_locales, :current_locale, :default_locale,
|
89
|
+
attr_accessor :built_in_locales, :current_locale, :default_locale,
|
90
|
+
:default_frontend_locale, :enabled, :locales
|
83
91
|
|
84
92
|
def enabled?
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
else
|
89
|
-
@enabled = RefinerySetting.find_or_set(:i18n_translation_enabled, true, {
|
90
|
-
:callback_proc_as_string => %q{::Refinery::I18n.setup!},
|
91
|
-
:scoping => 'refinery'
|
92
|
-
})
|
93
|
-
end
|
93
|
+
RefinerySetting.find_or_set(:i18n_translation_enabled, true, {
|
94
|
+
:scoping => 'refinery'
|
95
|
+
})
|
94
96
|
end
|
95
97
|
|
96
98
|
def current_locale
|
97
99
|
unless enabled?
|
98
100
|
::Refinery::I18n.current_locale = ::Refinery::I18n.default_locale
|
99
101
|
else
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
:callback_proc_as_string => %q{::Refinery::I18n.setup!}
|
104
|
-
})).to_sym
|
102
|
+
RefinerySetting.find_or_set(:i18n_translation_current_locale, ::Refinery::I18n.default_locale, {
|
103
|
+
:scoping => 'refinery'
|
104
|
+
}).to_sym
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
108
|
def current_locale=(locale)
|
109
|
-
@current_locale = locale.to_sym
|
110
109
|
value = {
|
111
110
|
:value => locale.to_sym,
|
112
|
-
:scoping => 'refinery'
|
113
|
-
:callback_proc_as_string => %q{::Refinery::I18n.setup!}
|
111
|
+
:scoping => 'refinery'
|
114
112
|
}
|
115
113
|
# handles a change in Refinery API
|
116
114
|
if RefinerySetting.methods.map(&:to_sym).include?(:set)
|
@@ -119,40 +117,31 @@ module Refinery
|
|
119
117
|
RefinerySetting[:i18n_translation_current_locale] = value
|
120
118
|
end
|
121
119
|
|
122
|
-
::I18n.locale =
|
120
|
+
::I18n.locale = locale.to_sym
|
123
121
|
end
|
124
122
|
|
125
123
|
def default_locale
|
126
|
-
|
127
|
-
:en, {
|
128
|
-
:callback_proc_as_string => %q{::Refinery::I18n.setup!},
|
124
|
+
RefinerySetting.find_or_set(:i18n_translation_default_locale, :en, {
|
129
125
|
:scoping => 'refinery'
|
130
|
-
})
|
126
|
+
}).to_sym
|
131
127
|
end
|
132
128
|
|
133
129
|
def default_frontend_locale
|
134
|
-
|
135
|
-
:
|
136
|
-
|
137
|
-
:callback_proc_as_string => %q{::Refinery::I18n.setup!}
|
138
|
-
})).to_sym
|
130
|
+
RefinerySetting.find_or_set(:i18n_translation_default_frontend_locale, :en, {
|
131
|
+
:scoping => 'refinery'
|
132
|
+
}).to_sym
|
139
133
|
end
|
140
134
|
|
141
135
|
def frontend_locales
|
142
|
-
|
143
|
-
|
144
|
-
:scoping => 'refinery',
|
145
|
-
:callback_proc_as_string => %q{::Refinery::I18n.setup!}
|
136
|
+
RefinerySetting.find_or_set(:i18n_translation_frontend_locales, [self.default_frontend_locale], {
|
137
|
+
:scoping => 'refinery'
|
146
138
|
})
|
147
139
|
end
|
148
140
|
|
149
141
|
def locales
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
:callback_proc_as_string => %q{::Refinery::I18n.setup!}
|
154
|
-
}
|
155
|
-
)
|
142
|
+
RefinerySetting.find_or_set(:i18n_translation_locales, self.built_in_locales, {
|
143
|
+
:scoping => 'refinery'
|
144
|
+
})
|
156
145
|
end
|
157
146
|
|
158
147
|
def has_locale?(locale)
|
@@ -160,15 +149,6 @@ module Refinery
|
|
160
149
|
end
|
161
150
|
|
162
151
|
def setup!
|
163
|
-
# Re-initialize variables.
|
164
|
-
@enabled = nil
|
165
|
-
@locales = nil
|
166
|
-
@default_locale = nil
|
167
|
-
@default_frontend_locale = nil
|
168
|
-
@current_locale = nil
|
169
|
-
@frontend_locales = nil
|
170
|
-
|
171
|
-
self.set_default_locale!
|
172
152
|
self.ensure_locales_up_to_date!
|
173
153
|
end
|
174
154
|
|
@@ -190,10 +170,6 @@ module Refinery
|
|
190
170
|
end
|
191
171
|
end
|
192
172
|
|
193
|
-
def set_default_locale!
|
194
|
-
::I18n.default_locale = ::Refinery::I18n.default_locale
|
195
|
-
end
|
196
|
-
|
197
173
|
end
|
198
174
|
|
199
175
|
@built_in_locales = {
|
@@ -215,7 +191,8 @@ module Refinery
|
|
215
191
|
:'zh-TW' => 'Traditional Chinese',
|
216
192
|
:el => 'Ελληνικά',
|
217
193
|
:rs => 'Srpski',
|
218
|
-
:cs => 'Česky'
|
194
|
+
:cs => 'Česky',
|
195
|
+
:sk => 'Slovenský'
|
219
196
|
}
|
220
197
|
end
|
221
198
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: refinerycms-i18n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.9.9.
|
5
|
+
version: 0.9.9.12
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Resolve Digital
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-03-10 00:00:00 +13:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -420,7 +420,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
420
420
|
requirements: []
|
421
421
|
|
422
422
|
rubyforge_project:
|
423
|
-
rubygems_version: 1.
|
423
|
+
rubygems_version: 1.6.1
|
424
424
|
signing_key:
|
425
425
|
specification_version: 3
|
426
426
|
summary: i18n logic for Refinery CMS.
|