fast_gettext 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fast_gettext/cache.rb +42 -0
  3. data/lib/fast_gettext/storage.rb +28 -55
  4. data/lib/fast_gettext/version.rb +1 -1
  5. metadata +105 -73
  6. data/.gitignore +0 -2
  7. data/.travis.yml +0 -17
  8. data/Appraisals +0 -8
  9. data/CHANGELOG +0 -8
  10. data/Gemfile +0 -10
  11. data/Gemfile.lock +0 -52
  12. data/Rakefile +0 -25
  13. data/Readme.md +0 -261
  14. data/benchmark/base.rb +0 -46
  15. data/benchmark/baseline.rb +0 -5
  16. data/benchmark/fast_gettext.rb +0 -18
  17. data/benchmark/i18n_simple.rb +0 -8
  18. data/benchmark/ideal.rb +0 -24
  19. data/benchmark/locale/de.yml +0 -126
  20. data/benchmark/locale/de/LC_MESSAGES/large.mo +0 -0
  21. data/benchmark/misc/threadsave.rb +0 -21
  22. data/benchmark/namespace/fast_gettext.rb +0 -15
  23. data/benchmark/namespace/original.rb +0 -14
  24. data/benchmark/original.rb +0 -22
  25. data/examples/db/migration.rb +0 -22
  26. data/examples/missing_translation_logger.rb +0 -13
  27. data/fast_gettext.gemspec +0 -12
  28. data/gemfiles/rails23.gemfile +0 -14
  29. data/gemfiles/rails23.gemfile.lock +0 -56
  30. data/gemfiles/rails32.gemfile +0 -14
  31. data/gemfiles/rails32.gemfile.lock +0 -112
  32. data/gemfiles/rails40.gemfile +0 -15
  33. data/gemfiles/rails40.gemfile.lock +0 -110
  34. data/spec/aa_unconfigued_spec.rb +0 -21
  35. data/spec/cases/fake_load_path/iconv.rb +0 -2
  36. data/spec/cases/iconv_fallback.rb +0 -22
  37. data/spec/cases/interpolate_i18n_after_fast_gettext.rb +0 -7
  38. data/spec/cases/interpolate_i18n_before_fast_gettext.rb +0 -9
  39. data/spec/cases/safe_mode_can_handle_locales.rb +0 -5
  40. data/spec/fast_gettext/mo_file_spec.rb +0 -35
  41. data/spec/fast_gettext/po_file_spec.rb +0 -35
  42. data/spec/fast_gettext/storage_spec.rb +0 -386
  43. data/spec/fast_gettext/translation_repository/base_spec.rb +0 -24
  44. data/spec/fast_gettext/translation_repository/chain_spec.rb +0 -98
  45. data/spec/fast_gettext/translation_repository/db_spec.rb +0 -114
  46. data/spec/fast_gettext/translation_repository/logger_spec.rb +0 -40
  47. data/spec/fast_gettext/translation_repository/mo_spec.rb +0 -58
  48. data/spec/fast_gettext/translation_repository/po_spec.rb +0 -65
  49. data/spec/fast_gettext/translation_repository/yaml_spec.rb +0 -84
  50. data/spec/fast_gettext/translation_repository_spec.rb +0 -33
  51. data/spec/fast_gettext/translation_spec.rb +0 -363
  52. data/spec/fast_gettext/vendor/iconv_spec.rb +0 -7
  53. data/spec/fast_gettext/vendor/string_spec.rb +0 -101
  54. data/spec/fast_gettext_spec.rb +0 -51
  55. data/spec/fuzzy_locale/de/test.po +0 -22
  56. data/spec/locale/de/LC_MESSAGES/test.mo +0 -0
  57. data/spec/locale/de/LC_MESSAGES/test2.mo +0 -0
  58. data/spec/locale/de/test.po +0 -74
  59. data/spec/locale/de/test2.po +0 -64
  60. data/spec/locale/en/LC_MESSAGES/plural_test.mo +0 -0
  61. data/spec/locale/en/LC_MESSAGES/test.mo +0 -0
  62. data/spec/locale/en/plural_test.po +0 -20
  63. data/spec/locale/en/test.po +0 -59
  64. data/spec/locale/gsw_CH/LC_MESSAGES/test.mo +0 -0
  65. data/spec/locale/gsw_CH/test.po +0 -61
  66. data/spec/locale/yaml/de.yml +0 -25
  67. data/spec/locale/yaml/de2.yml +0 -25
  68. data/spec/locale/yaml/en.yml +0 -21
  69. data/spec/locale/yaml/notfound.yml +0 -2
  70. data/spec/obsolete_locale/de/test.po +0 -21
  71. data/spec/spec_helper.rb +0 -42
  72. data/spec/support/be_accessible_matcher.rb +0 -8
@@ -1,33 +0,0 @@
1
- require "spec_helper"
2
-
3
- module FastGettext
4
- module TranslationRepository
5
- class Dummy
6
- attr_accessor :name, :options
7
- def initialize(name, options)
8
- @name = name
9
- @options = options
10
- end
11
- end
12
- end
13
- end
14
-
15
- describe FastGettext::TranslationRepository do
16
- describe "build" do
17
- it "auto requires class by default" do
18
- lambda { FastGettext::TranslationRepository.build('xx', { :type => 'invalid'}) }.should raise_error(LoadError)
19
- end
20
-
21
- it "can have auto-require disabled" do
22
- FastGettext::TranslationRepository.build('xx', { :type => 'dummy' })
23
- end
24
-
25
- it "makes a new repository" do
26
- options = { :type => 'dummy', :external => true }
27
- repo = FastGettext::TranslationRepository.build('xx', options)
28
- repo.class.should == FastGettext::TranslationRepository::Dummy
29
- repo.name.should == 'xx'
30
- repo.options.should == options
31
- end
32
- end
33
- end
@@ -1,363 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe FastGettext::Translation do
4
- include FastGettext::Translation
5
- include FastGettext::TranslationMultidomain
6
-
7
- before do
8
- default_setup
9
- end
10
-
11
- describe "unknown locale" do
12
- before do
13
- FastGettext.available_locales = nil
14
- FastGettext.locale = 'xx'
15
- end
16
-
17
- it "does not translate" do
18
- _('car').should == 'car'
19
- end
20
-
21
- it "does not translate plurals" do
22
- n_('car','cars',2).should == 'cars'
23
- end
24
- end
25
-
26
- describe :_ do
27
- it "translates simple text" do
28
- _('car').should == 'Auto'
29
- end
30
-
31
- it "returns the original string if its translation is blank" do
32
- _('Untranslated').should == 'Untranslated'
33
- end
34
-
35
- it "does not return the blank translation if a string's translation is blank" do
36
- _('Untranslated').should_not == ''
37
- end
38
-
39
- it "returns key if not translation was found" do
40
- _('NOT|FOUND').should == 'NOT|FOUND'
41
- end
42
-
43
- it "does not return the gettext meta information" do
44
- _('').should == ''
45
- end
46
-
47
- it "returns nil when specified" do
48
- _('not found'){nil}.should be_nil
49
- end
50
-
51
- it "returns block when specified" do
52
- _('not found'){:block}.should == :block
53
- end
54
- end
55
-
56
- describe :n_ do
57
- before do
58
- FastGettext.pluralisation_rule = nil
59
- end
60
-
61
- it "translates pluralized" do
62
- n_('Axis','Axis',1).should == 'Achse'
63
- n_('Axis','Axis',2).should == 'Achsen'
64
- n_('Axis','Axis',0).should == 'Achsen'
65
- end
66
-
67
- describe "pluralisations rules" do
68
- it "supports abstract pluralisation rules" do
69
- FastGettext.pluralisation_rule = lambda{|n|2}
70
- n_('a','b','c','d',4).should == 'c'
71
- end
72
-
73
- it "supports false as singular" do
74
- FastGettext.pluralisation_rule = lambda{|n|n!=2}
75
- n_('singular','plural','c','d',2).should == 'singular'
76
- end
77
-
78
- it "supports true as plural" do
79
- FastGettext.pluralisation_rule = lambda{|n|n==2}
80
- n_('singular','plural','c','d',2).should == 'plural'
81
- end
82
- end
83
-
84
- it "returns a simple translation when no combined was found" do
85
- n_('Axis','NOTFOUNDs',1).should == 'Achse'
86
- end
87
-
88
- it "returns the appropriate key if no translation was found" do
89
- n_('NOTFOUND','NOTFOUNDs',1).should == 'NOTFOUND'
90
- n_('NOTFOUND','NOTFOUNDs',2).should == 'NOTFOUNDs'
91
- end
92
-
93
- it "returns the last key when no translation was found and keys where to short" do
94
- FastGettext.pluralisation_rule = lambda{|x|4}
95
- n_('Apple','Apples',2).should == 'Apples'
96
- end
97
-
98
- it "returns block when specified" do
99
- n_('not found'){:block}.should == :block
100
- end
101
- end
102
-
103
- describe :s_ do
104
- it "translates simple text" do
105
- s_('car').should == 'Auto'
106
- end
107
-
108
- it "returns cleaned key if a translation was not found" do
109
- s_("XXX|not found").should == "not found"
110
- end
111
-
112
- it "can use a custom seperator" do
113
- s_("XXX/not found",'/').should == "not found"
114
- end
115
-
116
- it "returns block when specified" do
117
- s_('not found'){:block}.should == :block
118
- end
119
- end
120
-
121
- describe :N_ do
122
- it "returns the key" do
123
- N_('XXXXX').should == 'XXXXX'
124
- end
125
- end
126
-
127
- describe :Nn_ do
128
- it "returns the keys as array" do
129
- Nn_('X','Y').should == ['X','Y']
130
- end
131
- end
132
-
133
- describe :ns_ do
134
- it "translates whith namespace" do
135
- ns_('Fruit|Apple','Fruit|Apples',2).should == 'Apples'
136
- end
137
-
138
- it "returns block when specified" do
139
- ns_('not found'){:block}.should == :block
140
- ns_('not found'){nil}.should be_nil
141
- end
142
- end
143
-
144
- describe :multi_domain do
145
- before do
146
- setup_extra_domain
147
- end
148
-
149
- describe :_in_domain do
150
- it "changes domain via in_domain" do
151
- Thread.current[:fast_gettext_text_domain].should == "test"
152
- _in_domain "fake" do
153
- Thread.current[:fast_gettext_text_domain].should == "fake"
154
- end
155
- Thread.current[:fast_gettext_text_domain].should == "test"
156
- end
157
- end
158
-
159
- describe :d_ do
160
- it "translates simple text" do
161
- d_('test', 'car').should == 'Auto'
162
- end
163
-
164
- it "translates simple text in different domain" do
165
- d_('test2', 'car').should == 'Auto 2'
166
- end
167
-
168
- it "translates simple text in different domain one transaction" do
169
- d_('test', 'car').should == 'Auto'
170
- d_('test2', 'car').should == 'Auto 2'
171
- end
172
-
173
- it "returns the original string if its translation is blank" do
174
- d_('test', 'Untranslated').should == 'Untranslated'
175
- end
176
-
177
- it "sets text domain back to previous one" do
178
- old_domain = FastGettext.text_domain
179
- d_('test2', 'car').should == 'Auto 2'
180
- FastGettext.text_domain.should == old_domain
181
- end
182
-
183
- it "returns appropriate key if translation is not found in a domain" do
184
- FastGettext.translation_repositories['fake'] = {}
185
- d_('fake', 'car').should == 'car'
186
- end
187
- end
188
-
189
- describe :dn_ do
190
- before do
191
- FastGettext.pluralisation_rule = nil
192
- end
193
-
194
- it "translates pluralized" do
195
- dn_('test', 'Axis','Axis',1).should == 'Achse'
196
- dn_('test2', 'Axis','Axis',1).should == 'Achse 2'
197
- end
198
-
199
- it "returns a simple translation when no combined was found" do
200
- dn_('test', 'Axis','NOTFOUNDs',1).should == 'Achse'
201
- dn_('test2', 'Axis','NOTFOUNDs',1).should == 'Achse 2'
202
- end
203
-
204
- it "returns the appropriate key if no translation was found" do
205
- dn_('test', 'NOTFOUND','NOTFOUNDs',1).should == 'NOTFOUND'
206
- dn_('test', 'NOTFOUND','NOTFOUNDs',2).should == 'NOTFOUNDs'
207
- end
208
-
209
- it "returns the last key when no translation was found and keys where to short" do
210
- FastGettext.pluralisation_rule = lambda{|x|4}
211
- dn_('test', 'Apple','Apples',2).should == 'Apples'
212
- end
213
- end
214
-
215
- describe :ds_ do
216
- it "translates simple text" do
217
- ds_('test2', 'car').should == 'Auto 2'
218
- ds_('test', 'car').should == 'Auto'
219
- end
220
-
221
- it "returns cleaned key if a translation was not found" do
222
- ds_('test2', "XXX|not found").should == "not found"
223
- end
224
-
225
- it "can use a custom seperator" do
226
- ds_('test2', "XXX/not found",'/').should == "not found"
227
- end
228
- end
229
-
230
- describe :dns_ do
231
- it "translates whith namespace" do
232
- dns_('test', 'Fruit|Apple','Fruit|Apples',2).should == 'Apples'
233
- dns_('test2', 'Fruit|Apple','Fruit|Apples',2).should == 'Apples'
234
- end
235
- end
236
- end
237
-
238
- describe :multidomain_all do
239
- before do
240
- setup_extra_domain
241
- end
242
-
243
- describe :D_ do
244
- it "translates simple text" do
245
- D_('not found').should == 'not found'
246
- D_('only in test2 domain').should == 'nur in test2 Domain'
247
- end
248
-
249
- it "returns translation from random domain" do
250
- D_('car').should match('(Auto|Auto 2)')
251
- end
252
-
253
- it "sets text domain back to previous one" do
254
- old_domain = FastGettext.text_domain
255
- D_('car').should match('(Auto|Auto 2)')
256
- FastGettext.text_domain.should == old_domain
257
- end
258
- end
259
-
260
- describe :Dn_ do
261
- before do
262
- FastGettext.pluralisation_rule = nil
263
- end
264
-
265
- it "translates pluralized" do
266
- Dn_('Axis','Axis',1).should match('(Achse|Achse 2)')
267
- end
268
-
269
- it "returns a simple translation when no combined was found" do
270
- Dn_('Axis','NOTFOUNDs',1).should match('(Achse|Achse 2)')
271
- end
272
-
273
- it "returns the appropriate key if no translation was found" do
274
- Dn_('NOTFOUND','NOTFOUNDs',1).should == 'NOTFOUND'
275
- end
276
-
277
- it "returns the last key when no translation was found and keys where to short" do
278
- Dn_('Apple','Apples',2).should == 'Apples'
279
- end
280
- end
281
-
282
- describe :Ds_ do
283
- it "translates simple text" do
284
- Ds_('car').should match('(Auto|Auto 2)')
285
- end
286
-
287
- it "returns cleaned key if a translation was not found" do
288
- Ds_("XXX|not found").should == "not found"
289
- end
290
-
291
- it "can use a custom seperator" do
292
- Ds_("XXX/not found",'/').should == "not found"
293
- end
294
- end
295
-
296
- describe :Dns_ do
297
- it "translates whith namespace" do
298
- Dns_('Fruit|Apple','Fruit|Apples',1).should == 'Apple'
299
- Dns_('Fruit|Apple','Fruit|Apples',2).should == 'Apples'
300
- end
301
-
302
- it "returns cleaned key if a translation was not found" do
303
- Dns_("XXX|not found", "YYY|not found", 1).should == "not found"
304
- Dns_("XXX|not found", "YYY|not found", 2).should == "not found"
305
- end
306
- end
307
- end
308
-
309
- describe :caching do
310
- describe :cache_hit do
311
- before do
312
- #singular cache keys
313
- FastGettext.current_cache['xxx'] = '1'
314
-
315
- #plural cache keys
316
- FastGettext.current_cache['||||xxx'] = ['1','2']
317
- FastGettext.current_cache['||||xxx||||yyy'] = ['1','2']
318
- end
319
-
320
- it "uses the cache when translating with _" do
321
- _('xxx').should == '1'
322
- end
323
-
324
- it "uses the cache when translating with s_" do
325
- s_('xxx').should == '1'
326
- end
327
-
328
- it "uses the cache when translating with n_" do
329
- n_('xxx','yyy',1).should == '1'
330
- end
331
-
332
- it "uses the cache when translating with n_ and single argument" do
333
- n_('xxx',1).should == '1'
334
- end
335
- end
336
-
337
- it "caches different locales seperatly" do
338
- FastGettext.locale = 'en'
339
- _('car').should == 'car'
340
- FastGettext.locale = 'de'
341
- _('car').should == 'Auto'
342
- end
343
-
344
- it "caches different textdomains seperatly" do
345
- _('car').should == 'Auto'
346
-
347
- FastGettext.translation_repositories['fake'] = {}
348
- FastGettext.text_domain = 'fake'
349
- _('car').should == 'car'
350
-
351
- FastGettext.text_domain = 'test'
352
- _('car').should == 'Auto'
353
- end
354
-
355
- it "caches different textdomains seperatly for d_" do
356
- _('car').should == 'Auto'
357
-
358
- FastGettext.translation_repositories['fake'] = {}
359
- d_('fake', 'car').should == 'car'
360
- d_('test','car').should == 'Auto'
361
- end
362
- end
363
- end
@@ -1,7 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe 'Iconv' do
4
- it "also works when Iconv was not found locally" do
5
- system("bundle exec ruby spec/cases/iconv_fallback.rb").should == true
6
- end
7
- end
@@ -1,101 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe String do
4
- before :all do
5
- if "i18n gem overwrites % method".respond_to?(:interpolate_without_ruby_19_syntax)
6
- class String
7
- def %(*args)
8
- interpolate_without_ruby_19_syntax(*args)
9
- end
10
- end
11
- end
12
- end
13
-
14
- it "does not translate twice" do
15
- ("%{a} %{b}" % {:a=>'%{b}',:b=>'c'}).should == '%{b} c'
16
- end
17
-
18
- describe "old % style replacement" do
19
- it "substitudes using % + Hash" do
20
- ("x%{name}y" % {:name=>'a'}).should == 'xay'
21
- end
22
-
23
- it "does not substitute after %%" do
24
- ("%%{num} oops" % {:num => 1}).should == '%{num} oops'
25
- end
26
-
27
- it "does not substitute when nothing could be found" do
28
- ("abc" % {:x=>1}).should == 'abc'
29
- end
30
-
31
- if RUBY_VERSION < '1.9' # this does not longer work in 1.9, use :"my weird string"
32
- it "sustitutes strings" do
33
- ("a%{b}c" % {'b'=>1}).should == 'a1c'
34
- end
35
-
36
- it "sustitutes strings with -" do
37
- ("a%{b-a}c" % {'b-a'=>1}).should == 'a1c'
38
- end
39
-
40
- it "sustitutes string with ." do
41
- ("a%{b.a}c" % {'b.a'=>1}).should == 'a1c'
42
- end
43
-
44
- it "sustitutes string with number" do
45
- ("a%{1}c" % {'1'=>1}).should == 'a1c'
46
- end
47
- end
48
- end
49
-
50
- describe 'old sprintf style' do
51
- it "substitudes using % + Array" do
52
- ("x%sy%s" % ['a','b']).should == 'xayb'
53
- end
54
-
55
- if RUBY_VERSION < '1.9' # this does not longer work in 1.9, ArgumentError is raised
56
- it "does not remove %{} style replacements" do
57
- ("%{name} x%sy%s" % ['a','b']).should == '%{name} xayb'
58
- end
59
-
60
- it "does not remove %<> style replacement" do
61
- ("%{name} %<num>f %s" % ['x']).should == "%{name} %<num>f x"
62
- end
63
- end
64
- end
65
-
66
- describe 'ruby 1.9 style %< replacement' do
67
- it "does not substitute after %%" do
68
- ("%%<num> oops" % {:num => 1}).should == '%<num> oops'
69
- end
70
-
71
- it "subsitutes %<something>d" do
72
- ("x%<hello>dy" % {:hello=>1}).should == 'x1y'
73
- end
74
-
75
- it "substitutes #b" do
76
- ("%<num>#b" % {:num => 1}).should == "0b1"
77
- end
78
- end
79
-
80
- if RUBY_VERSION >= '1.9'
81
- it "does not raise when key was not found" do
82
- ("%{typo} xxx" % {:something=>1}).should == "%{typo} xxx"
83
- end
84
- end
85
-
86
- describe 'with i18n loaded' do
87
- let(:pending_condition) { (RUBY_VERSION < "1.9" and ActiveRecord::VERSION::MAJOR == 3) or ActiveRecord::VERSION::MAJOR >= 4 }
88
-
89
- it "interpolates if i18n is loaded before" do
90
- pending_if pending_condition, "does not work on ree + rails 3 or rails 4" do
91
- system("bundle exec ruby spec/cases/interpolate_i18n_before_fast_gettext.rb > /dev/null 2>&1").should == true
92
- end
93
- end
94
-
95
- it "interpolates if i18n is loaded before" do
96
- pending_if pending_condition, "does not work on ree + rails 3 or rails 4" do
97
- system("bundle exec ruby spec/cases/interpolate_i18n_after_fast_gettext.rb > /dev/null 2>&1").should == true
98
- end
99
- end
100
- end
101
- end