grosser-fast_gettext 0.2.1 → 0.2.2

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
@@ -44,6 +44,37 @@ GetText
44
44
  mapped: 9156K writeable/private: 6124K shared: 28K
45
45
 
46
46
 
47
+ Thread Safety and Rails
48
+ =======================
49
+ `text_domains` is not stored thread-save, so that they can be added inside the `environment.rb`,
50
+ and do not need to be readded for every thread (parsing takes time...).
51
+
52
+ Setting `available_locales`,`text_domain` or `locale` will not work inside the `evironment.rb`, since it runs in a different thread
53
+ then e.g. controllers, so set them inside your application_controller.
54
+
55
+ #environment.rb after initializers
56
+ FastGettext.add_text_domain('accounting',:path=>'locale')
57
+ FastGettext.add_text_domain('frontend',:path=>'locale')
58
+ ...
59
+
60
+ #application_controller.rb
61
+ FastGettext.available_locales = ['de','en',...]
62
+ FastGettext.text_domain = 'frontend'
63
+
64
+ class ApplicationController ...
65
+ include FastGettext
66
+ before_filter :set_locale
67
+ def set_locale
68
+ sessions[:locale] = I18n.locale = FastGettext.locale = params[:locale] || sessions[:locale] || 'en'
69
+ end
70
+
71
+ #application_helper.rb
72
+ module ApplicationHelper
73
+ include FastGettext
74
+ ...
75
+
76
+ Try the [gettext_i18n_rails plugin](http://github.com/grosser/gettext_i18n_rails), it simplifies the setup.
77
+
47
78
  Updating translations
48
79
  =====================
49
80
  ATM you have to use the [original GetText](http://github.com/mutoh/gettext) to create and manage your po/mo-files.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 2
3
- :patch: 1
3
+ :patch: 2
4
4
  :major: 0
@@ -1,6 +1,6 @@
1
1
  module FastGettext
2
2
  module Storage
3
- [:text_domain,:available_locales,:text_domains].each do |method|
3
+ [:text_domain,:available_locales].each do |method|
4
4
  define_method method do
5
5
  thread_store(method)
6
6
  end
@@ -9,6 +9,11 @@ module FastGettext
9
9
  end
10
10
  end
11
11
 
12
+ @@text_domains={}
13
+ def text_domains
14
+ @@text_domains
15
+ end
16
+
12
17
  def locale
13
18
  thread_store(:locale) || (available_locales||[]).first || 'en'
14
19
  end
data/lib/fast_gettext.rb CHANGED
@@ -63,6 +63,7 @@ module FastGettext
63
63
 
64
64
  private
65
65
 
66
+ #TODO geht nicht <-> {}.plural
66
67
  def current_mo
67
68
  mo = text_domains[text_domain][:mo_files][locale] rescue nil
68
69
  mo || {}
@@ -15,12 +15,19 @@ describe Storage do
15
15
  send(method) == 'de'
16
16
  end
17
17
 
18
- [:locale, :available_locales, :text_domain, :text_domains].each do |method|
18
+ [:locale, :available_locales, :text_domain].each do |method|
19
19
  it "stores #{method} thread-save" do
20
20
  thread_save(method).should == true
21
21
  end
22
22
  end
23
23
 
24
+ it "stores text_domains non-thread-safe" do
25
+ self.text_domains[:x]=1
26
+ t = Thread.new{self.text_domains[:x]=2}
27
+ t.join
28
+ self.text_domains[:x].should == 2
29
+ end
30
+
24
31
  describe :locale do
25
32
  it "stores everything as long as available_locales is not set" do
26
33
  self.available_locales = nil
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.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-19 00:00:00 -08:00
12
+ date: 2009-02-20 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15