grosser-fast_gettext 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,6 +1,8 @@
1
1
  FastGettext
2
2
  ===========
3
- GetText but 8.21 times faster, simple, clean namespace (7 vs 34) and threadsave!
3
+ GetText but 8 times faster, simple, clean namespace (7 vs 34) and threadsave!
4
+
5
+ [Example Rails application](https://github.com/grosser/gettext_i18n_rails_example)
4
6
 
5
7
  Setup
6
8
  =====
@@ -22,41 +24,37 @@ Start translating
22
24
  s_('Namespace|no-found') == 'not-found'
23
25
  n_('Axis','Axis',3) == 'Achsen' #German plural of Axis
24
26
 
27
+ Disable translation errors(like no text domain setup) while doing e.g. console session
28
+ FastGettext.silence_errors
29
+
25
30
  Speed
26
31
  =====
27
- 50_000 translations:
28
- Ideal: (primitive Hash lookup)
29
- small translation file:
30
- 1.080000 0.190000 1.270000 ( 1.274699)
31
- mapped: 5832K writeable/private: 3016K shared: 28K
32
-
33
- large translation file:
34
- 1.110000 0.200000 1.310000 ( 1.305616)
35
- mapped: 5832K writeable/private: 3016K shared: 28K
36
-
37
- FastGettext:
38
- small translation file:
39
- 1.980000 0.310000 2.290000 ( 2.285980)
40
- mapped: 5852K writeable/private: 3036K shared: 28K
41
-
42
- large translation file:
43
- 1.990000 0.320000 2.310000 ( 2.318801)
44
- mapped: 5852K writeable/private: 3036K shared: 28K
45
-
46
- GetText:
47
- small translation file:
48
- 16.210000 1.290000 17.500000 ( 17.511050)
49
- mapped: 8908K writeable/private: 5876K shared: 28K
50
-
51
- large translation file:
52
- 16.340000 1.330000 17.670000 ( 17.679807)
53
- mapped: 9028K writeable/private: 5996K shared: 28K
32
+ 50_000 translations
33
+ small translation file <-> large translation file
34
+ Baseline: (doing nothing in a loop)
35
+ 0.390000s / 2904K
36
+
37
+ Ideal: (primitive Hash lookup)
38
+ 1.010000s / 3016K <-> 1.040000s / 3016K
39
+
40
+ FastGettext:
41
+ 1.860000s / 3040K <-> 1.830000s / 3040K
42
+
43
+ GetText:
44
+ 14.880000s / 5816K <-> 14.810000s / 6008K
45
+
46
+ Rails I18n Simple:
47
+ 31.200000s / 10044K
48
+
54
49
 
55
50
  Thread Safety and Rails
56
51
  =======================
57
52
  `text_domains` is not stored thread-save, so that they can be added inside the `environment.rb`,
58
53
  and do not need to be readded for every thread (parsing takes time...).
59
54
 
55
+ ###Rails
56
+ Try the [gettext_i18n_rails plugin](http://github.com/grosser/gettext_i18n_rails), it simplifies the setup.
57
+
60
58
  Setting `available_locales`,`text_domain` or `locale` will not work inside the `evironment.rb`, since it runs in a different thread
61
59
  then e.g. controllers, so set them inside your application_controller.
62
60
 
@@ -72,7 +70,7 @@ then e.g. controllers, so set them inside your application_controller.
72
70
  def set_locale
73
71
  FastGettext.available_locales = ['de','en',...]
74
72
  FastGettext.text_domain = 'frontend'
75
- sessions[:locale] = I18n.locale = FastGettext.locale = params[:locale] || sessions[:locale] || 'en'
73
+ sessions[:locale] = I18n.locale = FastGettext.set_locale(params[:locale] || sessions[:locale] || 'en')
76
74
  end
77
75
 
78
76
  #application_helper.rb
@@ -80,8 +78,6 @@ then e.g. controllers, so set them inside your application_controller.
80
78
  include FastGettext::Translation
81
79
  ...
82
80
 
83
- Try the [gettext_i18n_rails plugin](http://github.com/grosser/gettext_i18n_rails), it simplifies the setup.
84
-
85
81
  Updating translations
86
82
  =====================
87
83
  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
- :minor: 2
3
- :patch: 6
4
2
  :major: 0
3
+ :minor: 2
4
+ :patch: 7
@@ -52,6 +52,13 @@ module FastGettext
52
52
  locale
53
53
  end
54
54
 
55
+ #turn off translation if none was defined to disable all resulting errors
56
+ def silence_errors
57
+ if not self.current_translations or self.current_translations == NoTextDomainConfigured
58
+ self.current_translations = MoFile.empty
59
+ end
60
+ end
61
+
55
62
  private
56
63
 
57
64
  def update_current_translations
@@ -2,6 +2,7 @@ require File.join(File.dirname(__FILE__),'spec_helper')
2
2
 
3
3
  describe 'unconfigured' do
4
4
  it "gives a useful error message when trying to just translate" do
5
+ FastGettext.text_domain = nil
5
6
  x=1
6
7
  begin
7
8
  FastGettext._('x')
@@ -54,4 +54,24 @@ describe Storage do
54
54
  self.set_locale('en').should == 'de'
55
55
  end
56
56
  end
57
+
58
+ describe :silence_errors do
59
+ before do
60
+ FastGettext.text_domain = 'xxx'
61
+ end
62
+ it "raises when a textdomain was empty" do
63
+ begin
64
+ FastGettext._('x')
65
+ x=2
66
+ rescue
67
+ x=1
68
+ end
69
+ x.should == 1
70
+ end
71
+
72
+ it "can silence erros" do
73
+ FastGettext.silence_errors
74
+ FastGettext._('x').should == 'x'
75
+ end
76
+ end
57
77
  end
@@ -16,4 +16,17 @@ describe FastGettext do
16
16
  N_('XXXXX').should == 'XXXXX'
17
17
  Nn_('X','Y').should == ['X','Y']
18
18
  end
19
+ it "is extended to a class and included into a class" do
20
+ class IncludeTest
21
+ include FastGettext::Translation
22
+ def self.ext
23
+ _('car')
24
+ end
25
+ def inc
26
+ _('car')
27
+ end
28
+ end
29
+ IncludeTest.ext.should == 'Auto'
30
+ IncludeTest.new.inc.should == 'Auto'
31
+ end
19
32
  end
data/vendor/iconv.rb CHANGED
@@ -21,11 +21,14 @@
21
21
  begin
22
22
  require 'iconv'
23
23
  rescue LoadError
24
- # Pseudo Iconv class
25
- #
26
- # Provides Iconv.iconv which uses Ruby/GLib(1) functions. This library also required from 'gettext'.
27
- # If you require 'gettext/iconv', Iconv.iconv try to call Ruby/GLib function
28
- # when it doesn't find original Iconv class(iconv.so).
24
+ # Provides Iconv.iconv which normally is provided through Ruby/GLib(1) functions.
25
+ # This library is required for 'gettext'.
26
+ # If you require 'gettext/iconv', it tries to call Ruby/GLib function
27
+ # when it doesn't find original Iconv class(iconv.so) it adds a pseudo class.
28
+ #
29
+ # One-click Ruby Installer for Win32 hadn’t had iconv and there hadn’t been a way to install iconv.so itself for Win32.
30
+ # And JRuby hadn’t had Iconv.
31
+ # I’ve not checked them currently, but if they’ve supported iconv now, we don’t need this anymore...
29
32
  #
30
33
  # (1) Ruby/GLib is a module which is provided from Ruby-GNOME2 Project.
31
34
  # You can get binaries for Win32(One-Click Ruby Installer).
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.6
4
+ version: 0.2.7
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-20 00:00:00 -08:00
12
+ date: 2009-02-24 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -22,37 +22,37 @@ extensions: []
22
22
  extra_rdoc_files: []
23
23
 
24
24
  files:
25
- - vendor/iconv.rb
26
- - vendor/string.rb
27
- - vendor/mofile.rb
28
- - vendor/empty.mo
29
- - vendor/README.rdoc
30
- - lib/fast_gettext.rb
25
+ - README.markdown
26
+ - VERSION.yml
31
27
  - lib/fast_gettext
32
- - lib/fast_gettext/translation.rb
33
- - lib/fast_gettext/storage.rb
28
+ - lib/fast_gettext.rb
34
29
  - lib/fast_gettext/mo_file.rb
30
+ - lib/fast_gettext/storage.rb
31
+ - lib/fast_gettext/translation.rb
32
+ - spec/aa_unconfigued_spec.rb
33
+ - spec/fast_gettext
34
+ - spec/fast_gettext/mo_file_spec.rb
35
+ - spec/fast_gettext/storage_spec.rb
36
+ - spec/fast_gettext/translation_spec.rb
35
37
  - spec/fast_gettext_spec.rb
36
- - spec/spec_helper.rb
37
38
  - spec/locale
38
- - spec/locale/en
39
- - spec/locale/en/LC_MESSAGES
40
- - spec/locale/en/LC_MESSAGES/test.mo
41
39
  - spec/locale/de
42
40
  - spec/locale/de/LC_MESSAGES
43
41
  - spec/locale/de/LC_MESSAGES/test.mo
44
- - spec/fast_gettext
45
- - spec/fast_gettext/translation_spec.rb
46
- - spec/fast_gettext/storage_spec.rb
47
- - spec/fast_gettext/mo_file_spec.rb
48
- - spec/aa_unconfigued_spec.rb
42
+ - spec/locale/en
43
+ - spec/locale/en/LC_MESSAGES
44
+ - spec/locale/en/LC_MESSAGES/test.mo
45
+ - spec/spec_helper.rb
49
46
  - spec/vendor
50
- - spec/vendor/iconv_spec.rb
51
47
  - spec/vendor/fake_load_path
52
48
  - spec/vendor/fake_load_path/iconv.rb
49
+ - spec/vendor/iconv_spec.rb
53
50
  - spec/vendor/string_spec.rb
54
- - VERSION.yml
55
- - README.markdown
51
+ - vendor/README.rdoc
52
+ - vendor/empty.mo
53
+ - vendor/iconv.rb
54
+ - vendor/mofile.rb
55
+ - vendor/string.rb
56
56
  has_rdoc: true
57
57
  homepage: http://github.com/grosser/fast_gettext
58
58
  post_install_message: