grosser-fast_gettext 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -108,11 +108,18 @@ Write your own TranslationRepository!
108
108
  end
109
109
  end
110
110
 
111
+ TODO
112
+ ====
113
+ - default_locale=(x) #atm the default is available_locales.first || 'en'
114
+ - default_text_domain=(x) #atm default is nil...
111
115
 
112
116
  Author
113
117
  ======
114
118
  Mo/Po-file parsing from Masao Mutoh, see vendor/README
115
119
 
120
+ ###Contributors
121
+ - [geekq](http://www.innoq.com/blog/vd)
122
+
116
123
  [Michael Grosser](http://pragmatig.wordpress.com)
117
124
  grosser.michael@gmail.com
118
125
  Hereby placed under public domain, do what you want, just do not hold me accountable...
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 3
4
- :patch: 3
4
+ :patch: 4
@@ -4,7 +4,11 @@ module FastGettext
4
4
  # - provide error messages when repositories are unconfigured
5
5
  # - accept/reject locales that are set by the user
6
6
  module Storage
7
- class NoTextDomainConfigured < Exception;end
7
+ class NoTextDomainConfigured < RuntimeError
8
+ def to_s
9
+ "Current textdomain (#{FastGettext.text_domain.inspect}) was not added, use FastGettext.add_text_domain!"
10
+ end
11
+ end
8
12
 
9
13
  [:available_locales,:text_domain,:_locale,:current_cache].each do |method_name|
10
14
  key = "fast_gettext_#{method_name}".to_sym
@@ -38,7 +42,7 @@ module FastGettext
38
42
  end
39
43
 
40
44
  def current_repository
41
- translation_repositories[text_domain] || NoTextDomainConfigured
45
+ translation_repositories[text_domain] || raise(NoTextDomainConfigured)
42
46
  end
43
47
 
44
48
  def locale
@@ -87,10 +91,8 @@ module FastGettext
87
91
 
88
92
  #turn off translation if none was defined to disable all resulting errors
89
93
  def silence_errors
90
- if not self.current_repository or self.current_repository == NoTextDomainConfigured
91
- require 'fast_gettext/translation_repository/base'
92
- translation_repositories[text_domain] = TranslationRepository::Base.new('x')
93
- end
94
+ require 'fast_gettext/translation_repository/base'
95
+ translation_repositories[text_domain] = TranslationRepository::Base.new('x')
94
96
  end
95
97
 
96
98
  private
@@ -101,4 +103,4 @@ module FastGettext
101
103
  self.current_cache = caches[text_domain][locale]
102
104
  end
103
105
  end
104
- end
106
+ end
@@ -3,22 +3,19 @@ require File.join(File.dirname(__FILE__),'spec_helper')
3
3
  describe 'unconfigured' do
4
4
  it "gives a useful error message when trying to just translate" do
5
5
  FastGettext.text_domain = nil
6
- x=1
7
6
  begin
8
7
  FastGettext._('x')
9
- rescue
10
- x=$!
8
+ "".should == "success!?"
9
+ rescue FastGettext::Storage::NoTextDomainConfigured
11
10
  end
12
- x.to_s.should =~ /NoTextDomainConfigured/
13
11
  end
12
+
14
13
  it "gives a useful error message when only locale was set" do
15
14
  FastGettext.locale = 'de'
16
- x=1
17
15
  begin
18
16
  FastGettext._('x')
19
- rescue
20
- x=$!
17
+ "".should == "success!?"
18
+ rescue FastGettext::Storage::NoTextDomainConfigured
21
19
  end
22
- x.to_s.should =~ /NoTextDomainConfigured/
23
20
  end
24
21
  end
@@ -87,11 +87,9 @@ describe 'Storage' do
87
87
  it "raises when a textdomain was empty" do
88
88
  begin
89
89
  FastGettext._('x')
90
- x=2
91
- rescue
92
- x=1
90
+ "".should == "success!?"
91
+ rescue FastGettext::Storage::NoTextDomainConfigured
93
92
  end
94
- x.should == 1
95
93
  end
96
94
 
97
95
  it "can silence erros" do
@@ -117,4 +115,20 @@ describe 'Storage' do
117
115
  FastGettext.current_cache['abc'].should == 'abc'
118
116
  end
119
117
  end
118
+
119
+ describe NoTextDomainConfigured do
120
+ it "shows what to do" do
121
+ NoTextDomainConfigured.new.to_s.should =~ /FastGettext\.add_text_domain/
122
+ end
123
+
124
+ it "warns when text_domain is nil" do
125
+ FastGettext.text_domain = nil
126
+ NoTextDomainConfigured.new.to_s.should =~ /\(nil\)/
127
+ end
128
+
129
+ it "shows current text_domain" do
130
+ FastGettext.text_domain = 'xxx'
131
+ NoTextDomainConfigured.new('xxx').to_s.should =~ /xxx/
132
+ end
133
+ end
120
134
  end
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.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
@@ -62,7 +62,6 @@ files:
62
62
  - spec/vendor/fake_load_path/iconv.rb
63
63
  - spec/vendor/iconv_spec.rb
64
64
  - spec/vendor/string_spec.rb
65
- - vendor/CHANGELOG
66
65
  - vendor/README.rdoc
67
66
  - vendor/empty.mo
68
67
  - vendor/iconv.rb
data/vendor/CHANGELOG DELETED
@@ -1 +0,0 @@
1
- 0.3 -- pluralisation methods accept/return n plural forms, contrary to singular/plural before