air18n 0.1.49 → 0.1.50
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/air18n/class_methods.rb +13 -0
- data/lib/air18n/prim_and_proper.rb +1 -1
- data/lib/air18n/version.rb +1 -1
- data/spec/lib/air18n/air18n_spec.rb +24 -14
- metadata +2 -2
data/lib/air18n/class_methods.rb
CHANGED
@@ -41,6 +41,19 @@ module Air18n
|
|
41
41
|
self.full_locale = locale
|
42
42
|
end
|
43
43
|
|
44
|
+
# Sets I18n.full_locale to specified locale, yields, then sets
|
45
|
+
# I18n.full_locale back to what it was.
|
46
|
+
#
|
47
|
+
# Useful for tests or where you want to render something in a
|
48
|
+
# certain language without the side-effect of changing
|
49
|
+
# I18n.full_locale.
|
50
|
+
def run_in_locale(locale)
|
51
|
+
old_locale = I18n.full_locale
|
52
|
+
I18n.full_locale = locale
|
53
|
+
yield
|
54
|
+
I18n.full_locale = old_locale
|
55
|
+
end
|
56
|
+
|
44
57
|
# Like ActionView::Helpers::TextHelper#pluralize, except requires that
|
45
58
|
# 'count' be a real number, not a string.
|
46
59
|
#
|
data/lib/air18n/version.rb
CHANGED
@@ -28,6 +28,18 @@ describe Air18n do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
context 'run_in_locale' do
|
32
|
+
it 'should work' do
|
33
|
+
old_locale = I18n.full_locale
|
34
|
+
I18n.full_locale = :pl
|
35
|
+
I18n.run_in_locale(:is) do
|
36
|
+
I18n.full_locale.should == :is
|
37
|
+
end
|
38
|
+
I18n.full_locale.should == :pl
|
39
|
+
I18n.full_locale = old_locale
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
31
43
|
context 'Keeping track of default routes context' do
|
32
44
|
it 'should start with blank routes context' do
|
33
45
|
I18n.translate('default route, key 1', :default => 'value 1', :locale => :en)
|
@@ -162,13 +174,12 @@ describe Air18n do
|
|
162
174
|
|
163
175
|
it 'should work in French' do
|
164
176
|
I18n.backend.store_translations(:fr, { 'shared.pluralize.Review' => '%{smart_count} Commentaire |||| %{smart_count} Commentaires' })
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
I18n.full_locale = old_locale
|
177
|
+
I18n.run_in_locale(:fr) do
|
178
|
+
I18n.pluralize(0, 'Review').should == '0 Commentaire'
|
179
|
+
I18n.pluralize(1, 'Review').should == '1 Commentaire'
|
180
|
+
I18n.pluralize(2, 'Review').should == '2 Commentaires'
|
181
|
+
I18n.pluralize(123.5, 'Review').should == '123.5 Commentaires'
|
182
|
+
end
|
172
183
|
end
|
173
184
|
|
174
185
|
it 'should work with explicitly-specified plural' do
|
@@ -178,13 +189,12 @@ describe Air18n do
|
|
178
189
|
I18n.pluralize(1, 'feis', 'feiseanna').should == '1 feis'
|
179
190
|
I18n.pluralize(2, 'feis', 'feiseanna').should == '2 feiseanna'
|
180
191
|
|
181
|
-
I18n.
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
I18n.full_locale = old_locale
|
192
|
+
I18n.run_in_locale(:fr) do
|
193
|
+
I18n.pluralize(0, 'feis', 'feiseanna').should == '0 french singular'
|
194
|
+
I18n.pluralize(1, 'feis', 'feiseanna').should == '1 french singular'
|
195
|
+
I18n.pluralize(2, 'feis', 'feiseanna').should == '2 french plural'
|
196
|
+
I18n.pluralize(123.5, 'feis', 'feiseanna').should == '123.5 french plural'
|
197
|
+
end
|
188
198
|
end
|
189
199
|
end
|
190
200
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: air18n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.50
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2013-01-
|
16
|
+
date: 2013-01-15 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: i18n
|