air18n 0.1.49 → 0.1.50

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
  #
@@ -145,7 +145,7 @@ module Air18n
145
145
  end
146
146
  end
147
147
 
148
- # Swiss German replaces "ß" with "ss".
148
+ # Swiss German replaces German "ß" with "ss".
149
149
  class GermanToSwissGerman
150
150
  def convert(text)
151
151
  text.gsub('ß', 'ss').gsub('ẞ', 'SS')
@@ -1,3 +1,3 @@
1
1
  module Air18n
2
- VERSION = "0.1.49"
2
+ VERSION = "0.1.50"
3
3
  end
@@ -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
- old_locale = I18n.full_locale
166
- I18n.full_locale = :fr
167
- I18n.pluralize(0, 'Review').should == '0 Commentaire'
168
- I18n.pluralize(1, 'Review').should == '1 Commentaire'
169
- I18n.pluralize(2, 'Review').should == '2 Commentaires'
170
- I18n.pluralize(123.5, 'Review').should == '123.5 Commentaires'
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.full_locale = :fr
182
- old_locale = I18n.full_locale
183
- I18n.pluralize(0, 'feis', 'feiseanna').should == '0 french singular'
184
- I18n.pluralize(1, 'feis', 'feiseanna').should == '1 french singular'
185
- I18n.pluralize(2, 'feis', 'feiseanna').should == '2 french plural'
186
- I18n.pluralize(123.5, 'feis', 'feiseanna').should == '123.5 french plural'
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.49
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-04 00:00:00.000000000 Z
16
+ date: 2013-01-15 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: i18n