grosser-fast_gettext 0.3.5 → 0.3.6

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.markdown CHANGED
@@ -100,6 +100,9 @@ plural definition (see spec/locale/en/test_plural.po or [Plural expressions for
100
100
  If you only use one text domain, setting `FastGettext.default_text_domain = 'app'`
101
101
  is sufficient and no more `text_domain=` is needed
102
102
 
103
+ ###default_locale
104
+ If the simple rule of "first `availble_locale` or 'en'" is not suficcient for you, simply set `FastGettext.default_locale = 'de'`.
105
+
103
106
  ###Plugins
104
107
  Want a yml, xml, database version ?
105
108
  Write your own TranslationRepository!
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 3
4
- :patch: 5
4
+ :patch: 6
@@ -61,7 +61,7 @@ module FastGettext
61
61
  end
62
62
 
63
63
  def locale
64
- _locale || (available_locales||[]).first || 'en'
64
+ _locale || ( default_locale || (available_locales||[]).first || 'en' )
65
65
  end
66
66
 
67
67
  def locale=(new_locale)
@@ -79,6 +79,17 @@ module FastGettext
79
79
  self.locale = new_locale
80
80
  locale
81
81
  end
82
+
83
+ @@default_locale = nil
84
+ def default_locale=(new_locale)
85
+ new_locale = best_locale_in(new_locale)
86
+ @@default_locale = new_locale
87
+ update_current_cache
88
+ end
89
+
90
+ def default_locale
91
+ @@default_locale
92
+ end
82
93
 
83
94
  #Opera: de-DE,de;q=0.9,en;q=0.8
84
95
  #Firefox de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
@@ -5,7 +5,14 @@ include FastGettext::Storage
5
5
 
6
6
  describe 'Storage' do
7
7
  before do
8
+ #reset everything to nil
8
9
  self.default_text_domain = nil
10
+ self.default_locale = nil
11
+ self.available_locales = nil
12
+ send(:_locale=,nil)#nil is not allowed to be set...
13
+ default_locale.should be_nil
14
+ available_locales.should be_nil
15
+ locale.should == 'en'
9
16
  end
10
17
 
11
18
  def thread_save(method)
@@ -32,12 +39,38 @@ describe 'Storage' do
32
39
  self.translation_repositories[:x].should == 2
33
40
  end
34
41
 
42
+ describe :default_locale do
43
+ it "stores default_locale non-thread-safe" do
44
+ thread_save(:default_locale).should == false
45
+ end
46
+
47
+ it "does not overwrite locale" do
48
+ self.locale = 'de'
49
+ self.default_locale = 'yy'
50
+ self.locale.should == 'de'
51
+ end
52
+
53
+ it "falls back to default if locale is missing" do
54
+ self.default_locale = 'yy'
55
+ self.locale.should == 'yy'
56
+ end
57
+
58
+ it "does not set non-available-locales as default" do
59
+ self.available_locales = ['xx']
60
+ self.default_locale = 'yy'
61
+ self.default_locale.should == nil
62
+ end
63
+
64
+ it "can set default_locale to nil" do
65
+ self.default_locale = 'xx'
66
+ self.default_locale = nil
67
+ default_locale.should be_nil
68
+ end
69
+ end
70
+
35
71
  describe :default_text_domain do
36
72
  it "stores default_text_domain non-thread-safe" do
37
- self.default_text_domain=1
38
- t = Thread.new{self.default_text_domain=2}
39
- t.join
40
- self.default_text_domain.should == 2
73
+ thread_save(:default_text_domain).should == false
41
74
  end
42
75
 
43
76
  it "uses default_text_domain when text_domain is not set" do
@@ -158,6 +191,13 @@ describe 'Storage' do
158
191
  FastGettext.current_cache['abc'].should == 'abc'
159
192
  end
160
193
 
194
+ it "cache is restored through setting of default_locale" do
195
+ FastGettext.send(:_locale=,nil)#reset locale to nil
196
+ FastGettext.default_locale = 'de'
197
+ FastGettext.locale.should == 'de'
198
+ FastGettext.current_cache['abc'].should == 'abc'
199
+ end
200
+
161
201
  it "stores a translation permanently" do
162
202
  FastGettext.locale = 'de'
163
203
  FastGettext.current_cache['abc'].should == 'abc'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grosser-fast_gettext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser