fast_gettext 0.7.0 → 0.7.1

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/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source "https://rubygems.org"
2
2
  gemspec
3
3
 
4
4
  gem 'appraisal'
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fast_gettext (0.7.0)
4
+ fast_gettext (0.7.1)
5
5
 
6
6
  GEM
7
- remote: http://rubygems.org/
7
+ remote: https://rubygems.org/
8
8
  specs:
9
9
  activemodel (3.2.8)
10
10
  activesupport (= 3.2.8)
data/Rakefile CHANGED
@@ -1,9 +1,10 @@
1
+ require 'bundler/setup'
1
2
  require 'bundler/gem_tasks'
2
3
  require 'bump/tasks'
3
4
  require 'appraisal'
4
5
 
5
6
  task :default do
6
- sh "bundle exec rake appraisal:install && bundle exec rake appraisal spec"
7
+ sh "rake appraisal:install && rake appraisal spec"
7
8
  end
8
9
 
9
10
  task :spec do
data/Readme.md CHANGED
@@ -225,8 +225,10 @@ Mo/Po-file parsing from Masao Mutoh, see vendor/README
225
225
  - [Hoang Nghiem](https://github.com/hoangnghiem)
226
226
  - [Costa Shapiro](https://github.com/costa)
227
227
  - [Jamie Dyer](https://github.com/kernow)
228
+ - [Stephan Kulow](https://github.com/coolo)
229
+ - [Fotos Georgiadis](https://github.com/fotos)
228
230
 
229
231
  [Michael Grosser](http://grosser.it)<br/>
230
232
  michael@grosser.it<br/>
231
- License: MIT<br/>
233
+ License: MIT, some vendor parts under the same license terms as Ruby (see headers)<br/>
232
234
  [![Build Status](https://travis-ci.org/grosser/fast_gettext.png)](https://travis-ci.org/grosser/fast_gettext)
data/fast_gettext.gemspec CHANGED
@@ -8,5 +8,5 @@ Gem::Specification.new name, FastGettext::VERSION do |s|
8
8
  s.email = "michael@grosser.it"
9
9
  s.homepage = "http://github.com/grosser/#{name}"
10
10
  s.files = `git ls-files`.split("\n")
11
- s.license = "MIT"
11
+ s.licenses = ["MIT", "Ruby"]
12
12
  end
@@ -1,6 +1,6 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source :rubygems
3
+ source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
6
  gem "rake"
@@ -4,7 +4,7 @@ PATH
4
4
  fast_gettext (0.7.0)
5
5
 
6
6
  GEM
7
- remote: http://rubygems.org/
7
+ remote: https://rubygems.org/
8
8
  specs:
9
9
  actionmailer (2.3.14)
10
10
  actionpack (= 2.3.14)
@@ -1,6 +1,6 @@
1
1
  # This file was generated by Appraisal
2
2
 
3
- source :rubygems
3
+ source "https://rubygems.org"
4
4
 
5
5
  gem "appraisal"
6
6
  gem "rake"
@@ -4,7 +4,7 @@ PATH
4
4
  fast_gettext (0.7.0)
5
5
 
6
6
  GEM
7
- remote: http://rubygems.org/
7
+ remote: https://rubygems.org/
8
8
  specs:
9
9
  actionmailer (3.2.8)
10
10
  actionpack (= 3.2.8)
@@ -72,6 +72,11 @@ module FastGettext
72
72
  Thread.current[:fast_gettext_current_cache] = cache
73
73
  end
74
74
 
75
+ def reload!
76
+ self.current_cache = {}
77
+ translation_repositories.values.each(&:reload)
78
+ end
79
+
75
80
  #global, since re-parsing whole folders takes too much time...
76
81
  @@translation_repositories={}
77
82
  def translation_repositories
@@ -25,6 +25,10 @@ module FastGettext
25
25
  current_translations.plural(*keys)
26
26
  end
27
27
 
28
+ def reload
29
+ true
30
+ end
31
+
28
32
  protected
29
33
 
30
34
  def current_translations
@@ -38,6 +38,11 @@ module FastGettext
38
38
  end
39
39
  []
40
40
  end
41
+
42
+ def reload
43
+ chain.each(&:reload)
44
+ super
45
+ end
41
46
  end
42
47
  end
43
- end
48
+ end
@@ -6,8 +6,8 @@ module FastGettext
6
6
  # - provide access to translations in mo files
7
7
  class Mo < Base
8
8
  def initialize(name,options={})
9
- find_and_store_files(name,options)
10
9
  super
10
+ reload
11
11
  end
12
12
 
13
13
  def available_locales
@@ -18,6 +18,11 @@ module FastGettext
18
18
  current_translations.pluralisation_rule
19
19
  end
20
20
 
21
+ def reload
22
+ find_and_store_files(@name, @options)
23
+ super
24
+ end
25
+
21
26
  protected
22
27
 
23
28
  def find_and_store_files(name,options)
@@ -8,8 +8,8 @@ module FastGettext
8
8
  # - provide access to translations in yaml files
9
9
  class Yaml < Base
10
10
  def initialize(name,options={})
11
- find_and_store_files(options)
12
11
  super
12
+ reload
13
13
  end
14
14
 
15
15
  def available_locales
@@ -26,6 +26,11 @@ module FastGettext
26
26
  self['pluralisation_rule'] ? lambda{|n| eval(self['pluralisation_rule']) } : nil
27
27
  end
28
28
 
29
+ def reload
30
+ find_and_store_files(@options)
31
+ super
32
+ end
33
+
29
34
  protected
30
35
 
31
36
  MAX_FIND_DEPTH = 10
@@ -69,4 +74,4 @@ module FastGettext
69
74
  end
70
75
  end
71
76
  end
72
- end
77
+ end
@@ -1,3 +1,3 @@
1
1
  module FastGettext
2
- VERSION = Version = '0.7.0'
2
+ VERSION = Version = '0.7.1'
3
3
  end
@@ -23,14 +23,14 @@ describe 'Storage' do
23
23
  text_domain.should == 'xxx'
24
24
  end
25
25
 
26
- def thread_save(method, value_a, value_b)
26
+ def thread_safe(method, value_a, value_b)
27
27
  send("#{method}=",value_a)
28
28
 
29
29
  # mess around with other threads
30
30
  100.times do
31
31
  Thread.new {FastGettext.send("#{method}=",value_b)}
32
32
  end
33
- sleep 0.1 # Ruby 1.9 cannot switch threads fat enough <-> spec fails without this WTF!
33
+ sleep 0.1 # Ruby 1.9 cannot switch threads fast enough <-> spec fails without this WTF!
34
34
 
35
35
  !!(send(method) == value_a)
36
36
  end
@@ -41,16 +41,22 @@ describe 'Storage' do
41
41
  :text_domain=>['xx','yy'],
42
42
  :pluralisation_rule=>[lambda{|x|x==4},lambda{|x|x==1}]
43
43
  }.each do |method, (value_a, value_b)|
44
- it "stores #{method} thread-save" do
45
- thread_save(method, value_a, value_b).should == true
44
+ it "stores #{method} thread safe" do
45
+ thread_safe(method, value_a, value_b).should == true
46
46
  end
47
47
  end
48
48
 
49
- it "stores translation_repositories non-thread-safe" do
50
- self.translation_repositories[:x]=1
51
- t = Thread.new{self.translation_repositories[:x]=2}
52
- t.join
53
- self.translation_repositories[:x].should == 2
49
+ context "non-thread safe" do
50
+ after do
51
+ self.translation_repositories.clear
52
+ end
53
+
54
+ it "stores translation_repositories" do
55
+ self.translation_repositories[:x]=1
56
+ t = Thread.new{self.translation_repositories[:x]=2}
57
+ t.join
58
+ self.translation_repositories[:x].should == 2
59
+ end
54
60
  end
55
61
 
56
62
  describe :pluralisation_rule do
@@ -65,7 +71,7 @@ describe 'Storage' do
65
71
 
66
72
  describe :default_locale do
67
73
  it "stores default_locale non-thread-safe" do
68
- thread_save(:default_locale, 'de', 'en').should == false
74
+ thread_safe(:default_locale, 'de', 'en').should == false
69
75
  end
70
76
 
71
77
  it "does not overwrite locale" do
@@ -93,8 +99,8 @@ describe 'Storage' do
93
99
  end
94
100
 
95
101
  describe :default_text_domain do
96
- it "stores default_text_domain non-thread-safe" do
97
- thread_save(:default_text_domain, 'xx', 'en').should == false
102
+ it "stores default_text_domain non-thread safe" do
103
+ thread_safe(:default_text_domain, 'xx', 'en').should == false
98
104
  end
99
105
 
100
106
  it "uses default_text_domain when text_domain is not set" do
@@ -112,7 +118,7 @@ describe 'Storage' do
112
118
 
113
119
  describe :default_available_locales do
114
120
  it "stores default_available_locales non-thread-safe" do
115
- thread_save(:default_available_locales, ['xx'], ['yy']).should == false
121
+ thread_safe(:default_available_locales, ['xx'], ['yy']).should == false
116
122
  end
117
123
 
118
124
  it "converts locales to s" do
@@ -216,6 +222,10 @@ describe 'Storage' do
216
222
  self.text_domain = rand(99999).to_s
217
223
  end
218
224
 
225
+ after do
226
+ self.translation_repositories.clear
227
+ end
228
+
219
229
  it "raises when a textdomain was empty" do
220
230
  begin
221
231
  FastGettext._('x')
@@ -288,6 +298,22 @@ describe 'Storage' do
288
298
  end
289
299
  end
290
300
 
301
+ describe :reload! do
302
+ it "reloads all repositories" do
303
+ FastGettext.translation_repositories.each do |name, repository|
304
+ repository.should_receive(:reload)
305
+ end
306
+
307
+ FastGettext.reload!
308
+ end
309
+
310
+ it "clears the cache" do
311
+ FastGettext.should_receive(:current_cache=).with({})
312
+
313
+ FastGettext.reload!
314
+ end
315
+ end
316
+
291
317
  describe :key_exist? do
292
318
  it "does not find default keys" do
293
319
  FastGettext._('abcde')
@@ -17,4 +17,8 @@ describe 'FastGettext::TranslationRepository::Base' do
17
17
  it "cannot pluralize" do
18
18
  @rep.plural('Axis','Axis').should == []
19
19
  end
20
+
21
+ it "can be reloaded" do
22
+ @rep.reload.should be_true
23
+ end
20
24
  end
@@ -27,6 +27,10 @@ describe 'FastGettext::TranslationRepository::Chain' do
27
27
  it "has no pluralisation rule" do
28
28
  @rep.pluralisation_rule.should == nil
29
29
  end
30
+
31
+ it "returns true on reload" do
32
+ @rep.reload.should be_true
33
+ end
30
34
  end
31
35
 
32
36
  describe "filled chain" do
@@ -77,5 +81,18 @@ describe 'FastGettext::TranslationRepository::Chain' do
77
81
  @rep.pluralisation_rule.should == 'x'
78
82
  end
79
83
  end
84
+
85
+ describe :reload do
86
+ it "reloads all repositories" do
87
+ @one.should_receive(:reload)
88
+ @two.should_receive(:reload)
89
+ @rep.reload
90
+ end
91
+
92
+ it "returns true" do
93
+ @rep.chain.each { |c| c.stub(:reload) }
94
+ @rep.reload.should be_true
95
+ end
96
+ end
80
97
  end
81
98
  end
@@ -20,6 +20,29 @@ describe 'FastGettext::TranslationRepository::Mo' do
20
20
  @rep.plural('Axis','Axis').should == ['Achse','Achsen']
21
21
  end
22
22
 
23
+ describe :reload do
24
+ before do
25
+ mo_file = FastGettext::MoFile.new('spec/locale/de/LC_MESSAGES/test2.mo')
26
+
27
+ FastGettext::MoFile.stub(:new).and_return(FastGettext::MoFile.empty)
28
+ FastGettext::MoFile.stub(:new).with('spec/locale/de/LC_MESSAGES/test.mo').and_return(mo_file)
29
+ end
30
+
31
+ it "can reload" do
32
+ FastGettext.locale = 'de'
33
+
34
+ @rep['Untranslated'].should be_nil
35
+
36
+ @rep.reload
37
+
38
+ @rep['Untranslated'].should == 'Translated'
39
+ end
40
+
41
+ it "returns true" do
42
+ @rep.reload.should be_true
43
+ end
44
+ end
45
+
23
46
  it "has access to the mo repositories pluralisation rule" do
24
47
  FastGettext.locale = 'en'
25
48
  rep = FastGettext::TranslationRepository.build('plural_test',:path=>File.join('spec','locale'))
@@ -33,6 +33,29 @@ describe 'FastGettext::TranslationRepository::Yaml' do
33
33
  @rep.plural('cars.axis').should == ['Achse', 'Achsen', nil, nil]
34
34
  end
35
35
 
36
+ describe :reload do
37
+ before do
38
+ yaml = YAML.load_file('spec/locale/yaml/de2.yml')
39
+
40
+ YAML.stub(:load_file).and_return('en' => {}, 'de' => {})
41
+ YAML.stub(:load_file).with('spec/locale/yaml/de.yml').and_return(yaml)
42
+ end
43
+
44
+ it "can reload" do
45
+ FastGettext.locale = 'de'
46
+
47
+ @rep['cars.car'].should == 'Auto'
48
+
49
+ @rep.reload
50
+
51
+ @rep['cars.car'].should == 'Aufzugskabine'
52
+ end
53
+
54
+ it "returns true" do
55
+ @rep.reload.should be_true
56
+ end
57
+ end
58
+
36
59
  it "handles unfound plurals with nil" do
37
60
  @rep.plural('cars.xxx').should == [nil, nil, nil, nil]
38
61
  end
@@ -24,6 +24,9 @@ describe FastGettext do
24
24
  it "provides access to FastGettext::Translations methods" do
25
25
  FastGettext._('car').should == 'Auto'
26
26
  _('car').should == 'Auto'
27
+ _("%{relative_time} ago").should == "vor %{relative_time}"
28
+ (_("%{relative_time} ago") % {:relative_time => 1}).should == "vor 1"
29
+ (N_("%{relative_time} ago") % {:relative_time => 1}).should == "1 ago"
27
30
  s_("XXX|not found").should == "not found"
28
31
  n_('Axis','Axis',1).should == 'Achse'
29
32
  N_('XXXXX').should == 'XXXXX'
Binary file
@@ -0,0 +1,71 @@
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the PACKAGE package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: version 0.0.1\n"
10
+ "POT-Creation-Date: 2009-02-26 19:50+0100\n"
11
+ "PO-Revision-Date: 2011-12-04 18:54+0900\n"
12
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
+ "Language-Team: LANGUAGE <LL@li.org>\n"
14
+ "MIME-Version: 1.0\n"
15
+ "Content-Type: text/plain; charset=UTF-8\n"
16
+ "Content-Transfer-Encoding: 8bit\n"
17
+ "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
18
+
19
+ #: app/helpers/translation_helper.rb:3
20
+ msgid "%{relative_time} ago"
21
+ msgstr "vor %{relative_time}"
22
+
23
+ #: app/views/cars/show.html.erb:5
24
+ msgid "Axis"
25
+ msgid_plural "Axis"
26
+ msgstr[0] "Achse"
27
+ msgstr[1] "Achsen"
28
+
29
+ #: app/controllers/cars_controller.rb:47
30
+ msgid "Car was successfully created."
31
+ msgstr "Auto wurde erfolgreich gespeichert"
32
+
33
+ #: app/controllers/cars_controller.rb:64
34
+ msgid "Car was successfully updated."
35
+ msgstr "Auto wurde erfolgreich aktualisiert"
36
+
37
+ #: app/views/cars/show.html.erb:1 locale/model_attributes.rb:3
38
+ msgid "Car|Model"
39
+ msgstr "Modell"
40
+
41
+ msgid "Untranslated"
42
+ msgstr "Translated"
43
+
44
+ #: app/views/cars/show.html.erb:3 locale/model_attributes.rb:4
45
+ msgid "Car|Wheels count"
46
+ msgstr "Räderzahl"
47
+
48
+ #: app/views/cars/show.html.erb:7
49
+ msgid "Created"
50
+ msgstr "Erstellt"
51
+
52
+ #: app/views/cars/show.html.erb:9
53
+ msgid "Month"
54
+ msgstr "Monat"
55
+
56
+ #: locale/model_attributes.rb:2
57
+ msgid "car"
58
+ msgstr "Auto"
59
+
60
+ #: locale/testlog_phrases.rb:2
61
+ msgid "this is a dynamic translation which was found thorugh gettext_test_log!"
62
+ msgstr ""
63
+ "Dies ist eine dynamische Übersetzung, die durch gettext_test_log "
64
+ "gefunden wurde!"
65
+
66
+ #: locale/test_escape.rb:2
67
+ msgid "You should escape '\\' as '\\\\'."
68
+ msgstr "Du solltest '\\' als '\\\\' escapen."
69
+
70
+ msgid "Umläüte"
71
+ msgstr "Umlaute"
@@ -0,0 +1,25 @@
1
+ de:
2
+ simple: einfach
3
+ date:
4
+ relative: "vor %{relative_time}"
5
+
6
+ cars:
7
+ axis:
8
+ one: "Achse"
9
+ other: "Achsen"
10
+ silly:
11
+ one: '0'
12
+ other: '1'
13
+ plural2: '2'
14
+ plural3: '3'
15
+ model: "Modell"
16
+ wheel_count: "Räderzahl"
17
+ created: "Erstellt"
18
+ month: "Monat"
19
+ car: "Aufzugskabine"
20
+ messages:
21
+ created: "Auto wurde erfolgreich gespeichert"
22
+ updated: "Auto wurde erfolgreich aktualisiert"
23
+
24
+ test_log:
25
+ phrases: "Dies ist eine dynamische Übersetzung, die durch gettext_test_log gefunden wurde!"
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_gettext
3
3
  version: !ruby/object:Gem::Version
4
+ version: 0.7.1
4
5
  prerelease:
5
- version: 0.7.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Michael Grosser
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-20 00:00:00.000000000 Z
12
+ date: 2013-06-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: michael@grosser.it
@@ -88,7 +88,9 @@ files:
88
88
  - spec/fast_gettext_spec.rb
89
89
  - spec/fuzzy_locale/de/test.po
90
90
  - spec/locale/de/LC_MESSAGES/test.mo
91
+ - spec/locale/de/LC_MESSAGES/test2.mo
91
92
  - spec/locale/de/test.po
93
+ - spec/locale/de/test2.po
92
94
  - spec/locale/en/LC_MESSAGES/plural_test.mo
93
95
  - spec/locale/en/LC_MESSAGES/test.mo
94
96
  - spec/locale/en/plural_test.po
@@ -96,6 +98,7 @@ files:
96
98
  - spec/locale/gsw_CH/LC_MESSAGES/test.mo
97
99
  - spec/locale/gsw_CH/test.po
98
100
  - spec/locale/yaml/de.yml
101
+ - spec/locale/yaml/de2.yml
99
102
  - spec/locale/yaml/en.yml
100
103
  - spec/locale/yaml/notfound.yml
101
104
  - spec/obsolete_locale/de/test.po
@@ -104,31 +107,32 @@ files:
104
107
  homepage: http://github.com/grosser/fast_gettext
105
108
  licenses:
106
109
  - MIT
110
+ - Ruby
107
111
  post_install_message:
108
112
  rdoc_options: []
109
113
  require_paths:
110
114
  - lib
111
115
  required_ruby_version: !ruby/object:Gem::Requirement
116
+ none: false
112
117
  requirements:
113
118
  - - ! '>='
114
119
  - !ruby/object:Gem::Version
115
120
  version: '0'
116
121
  segments:
117
122
  - 0
118
- hash: -2722134200546875497
119
- none: false
123
+ hash: 278086574654590991
120
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
+ none: false
121
126
  requirements:
122
127
  - - ! '>='
123
128
  - !ruby/object:Gem::Version
124
129
  version: '0'
125
130
  segments:
126
131
  - 0
127
- hash: -2722134200546875497
128
- none: false
132
+ hash: 278086574654590991
129
133
  requirements: []
130
134
  rubyforge_project:
131
- rubygems_version: 1.8.24
135
+ rubygems_version: 1.8.25
132
136
  signing_key:
133
137
  specification_version: 3
134
138
  summary: A simple, fast, memory-efficient and threadsafe implementation of GetText