grosser-fast_gettext 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +15 -9
- data/VERSION.yml +1 -1
- data/lib/fast_gettext/storage.rb +12 -12
- metadata +2 -2
data/README.markdown
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
FastGettext
|
2
2
|
===========
|
3
|
-
GetText but
|
3
|
+
GetText but 8 x faster, 72 x less memory, simple, clean namespace (7 vs 34) and threadsave!
|
4
4
|
|
5
5
|
[Example Rails application](https://github.com/grosser/gettext_i18n_rails_example)
|
6
6
|
|
@@ -39,19 +39,20 @@ Performance
|
|
39
39
|
50_000 translations speed / memory
|
40
40
|
small translation file <-> large translation file
|
41
41
|
Baseline: (doing nothing in a loop)
|
42
|
-
0.
|
42
|
+
0.420000s / 0K <->
|
43
43
|
|
44
44
|
Ideal: (primitive Hash lookup)
|
45
|
-
1.
|
45
|
+
1.170000s / 112K <-> 1.170000s / 112K
|
46
46
|
|
47
47
|
FastGettext:
|
48
|
-
|
48
|
+
1.960000s / 136K <-> 1.950000s / 268K
|
49
49
|
|
50
50
|
GetText 2.0:
|
51
|
-
15.
|
51
|
+
15.490000s / 8872K <-> 15.510000s / 9336K
|
52
52
|
|
53
53
|
ActiveSupport I18n::Backend::Simple :
|
54
|
-
32.
|
54
|
+
32.470000s / 9484K <->
|
55
|
+
|
55
56
|
|
56
57
|
|
57
58
|
|
@@ -88,7 +89,8 @@ then e.g. controllers, so set them inside your application_controller.
|
|
88
89
|
|
89
90
|
Updating translations
|
90
91
|
=====================
|
91
|
-
ATM you have to use the [original GetText](http://github.com/mutoh/gettext) to create and manage your po/mo-files.
|
92
|
+
ATM you have to use the [original GetText](http://github.com/mutoh/gettext) to create and manage your po/mo-files.
|
93
|
+
I already started work on a po/mo parser & reader that is easier to use, contributions welcome @ [pomo](http://github.com/grosser/pomo)
|
92
94
|
|
93
95
|
Advanced features
|
94
96
|
=================
|
@@ -115,10 +117,14 @@ Write your own TranslationRepository!
|
|
115
117
|
end
|
116
118
|
end
|
117
119
|
|
120
|
+
FAQ
|
121
|
+
===
|
122
|
+
- [Problems with ActiveRecord messages?](http://wiki.github.com/grosser/fast_gettext/activerecord)
|
123
|
+
|
118
124
|
TODO
|
119
125
|
====
|
120
|
-
- default_locale=(x)
|
121
|
-
- default_text_domain=(x)
|
126
|
+
- use `default_locale=(x)` internally, atm the default is available_locales.first || 'en'
|
127
|
+
- use `default_text_domain=(x)` internally, atm default is nil...
|
122
128
|
|
123
129
|
Author
|
124
130
|
======
|
data/VERSION.yml
CHANGED
data/lib/fast_gettext/storage.rb
CHANGED
@@ -10,26 +10,29 @@ module FastGettext
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
[:available_locales
|
13
|
+
[:available_locales, :_locale, :text_domain].each do |method_name|
|
14
14
|
key = "fast_gettext_#{method_name}".to_sym
|
15
15
|
define_method method_name do
|
16
16
|
Thread.current[key]
|
17
17
|
end
|
18
|
+
|
18
19
|
define_method "#{method_name}=" do |value|
|
19
20
|
Thread.current[key]=value
|
21
|
+
update_current_cache
|
20
22
|
end
|
21
23
|
end
|
22
24
|
private :_locale, :_locale=
|
23
|
-
#so initial translations does not crash
|
24
|
-
Thread.current[:fast_gettext_current_cache]={}
|
25
25
|
|
26
26
|
def text_domain
|
27
27
|
Thread.current[:fast_gettext_text_domain] || default_text_domain
|
28
28
|
end
|
29
29
|
|
30
|
-
def
|
31
|
-
Thread.current[:
|
32
|
-
|
30
|
+
def current_cache
|
31
|
+
Thread.current[:fast_gettext_current_cache] || {}
|
32
|
+
end
|
33
|
+
|
34
|
+
def current_cache=(cache)
|
35
|
+
Thread.current[:fast_gettext_current_cache] = cache
|
33
36
|
end
|
34
37
|
|
35
38
|
#-> cattr_accessor :default_text_domain
|
@@ -66,10 +69,7 @@ module FastGettext
|
|
66
69
|
|
67
70
|
def locale=(new_locale)
|
68
71
|
new_locale = best_locale_in(new_locale)
|
69
|
-
if new_locale
|
70
|
-
self._locale = new_locale
|
71
|
-
update_current_cache
|
72
|
-
end
|
72
|
+
self._locale = new_locale if new_locale
|
73
73
|
end
|
74
74
|
|
75
75
|
# for chaining: puts set_locale('xx') == 'xx' ? 'applied' : 'rejected'
|
@@ -124,8 +124,8 @@ module FastGettext
|
|
124
124
|
private
|
125
125
|
|
126
126
|
def update_current_cache
|
127
|
-
caches[text_domain]||={}
|
128
|
-
caches[text_domain][locale]||={}
|
127
|
+
caches[text_domain] ||= {}
|
128
|
+
caches[text_domain][locale] ||= {}
|
129
129
|
self.current_cache = caches[text_domain][locale]
|
130
130
|
end
|
131
131
|
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.
|
4
|
+
version: 0.3.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-
|
12
|
+
date: 2009-04-04 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|