i18nema 0.0.6 → 0.0.7
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.md +23 -24
- data/lib/i18nema.rb +17 -14
- metadata +2 -2
data/README.md
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Fast I18n backend to keep things running smoothly.
|
4
4
|
|
5
5
|
I18nema is a drop-in replacement for I18n::Backend::Simple, for faster
|
6
|
-
lookups (
|
6
|
+
lookups (15-20%) and quicker GC runs (ymmv). Translations are stored
|
7
7
|
outside of the ruby heap, and lookups happen in C (rather than the usual
|
8
8
|
inject on nested ruby hashes).
|
9
9
|
|
@@ -52,13 +52,13 @@ is nicer on ObjectSpace than vanilla I18n.
|
|
52
52
|
|
53
53
|
### Faster Translation Lookups
|
54
54
|
|
55
|
-
Simple lookups (i.e. no options or interpolation) take
|
56
|
-
time
|
57
|
-
(e.g. `foo.bar.baz.lol`).
|
55
|
+
Simple lookups (i.e. no options or interpolation) take a bit over 15%
|
56
|
+
less time.
|
58
57
|
|
59
|
-
Lookups with options
|
60
|
-
|
61
|
-
|
58
|
+
Lookups with options see slightly bigger gains (over 20% less time), in
|
59
|
+
part due to some speedups on the ruby side of things (I18n uses
|
60
|
+
`Hash#except`, which is quite slow when you have a long list of
|
61
|
+
arguments).
|
62
62
|
|
63
63
|
## Show me the benchmarks
|
64
64
|
|
@@ -72,37 +72,36 @@ e.g. `I18n.t('foo') -> 1`, `I18n.t('foo.bar') -> 2`
|
|
72
72
|
#### I18nema
|
73
73
|
|
74
74
|
user system total real
|
75
|
-
translate(1): 0.
|
76
|
-
translate(2): 1.
|
77
|
-
translate(3): 1.
|
78
|
-
translate(4): 1.
|
75
|
+
translate(1): 0.900000 0.010000 0.910000 ( 0.910228)
|
76
|
+
translate(2): 1.010000 0.010000 1.020000 ( 1.009545)
|
77
|
+
translate(3): 1.020000 0.010000 1.030000 ( 1.028098)
|
78
|
+
translate(4): 1.210000 0.000000 1.210000 ( 1.214737)
|
79
79
|
|
80
80
|
#### I18n
|
81
81
|
|
82
82
|
user system total real
|
83
|
-
translate(1):
|
84
|
-
translate(2):
|
85
|
-
translate(3):
|
86
|
-
translate(4):
|
83
|
+
translate(1): 1.000000 0.000000 1.000000 ( 1.007367)
|
84
|
+
translate(2): 1.260000 0.000000 1.260000 ( 1.268323)
|
85
|
+
translate(3): 1.320000 0.000000 1.320000 ( 1.315132)
|
86
|
+
translate(4): 1.390000 0.010000 1.400000 ( 1.393478)
|
87
87
|
|
88
88
|
### `translate` with options (locale, interpolation)
|
89
89
|
|
90
90
|
#### I18nema
|
91
91
|
|
92
92
|
user system total real
|
93
|
-
translate(1):
|
94
|
-
translate(2): 1.
|
95
|
-
translate(3): 1.
|
96
|
-
translate(4):
|
93
|
+
translate(1): 0.950000 0.000000 0.950000 ( 0.943904)
|
94
|
+
translate(2): 1.040000 0.000000 1.040000 ( 1.036595)
|
95
|
+
translate(3): 1.060000 0.010000 1.070000 ( 1.059588)
|
96
|
+
translate(4): 1.240000 0.000000 1.240000 ( 1.237322)
|
97
97
|
|
98
98
|
#### I18n
|
99
99
|
|
100
100
|
user system total real
|
101
|
-
translate(1):
|
102
|
-
translate(2):
|
103
|
-
translate(3):
|
104
|
-
translate(4):
|
105
|
-
|
101
|
+
translate(1): 1.090000 0.000000 1.090000 ( 1.099866)
|
102
|
+
translate(2): 1.360000 0.000000 1.360000 ( 1.364869)
|
103
|
+
translate(3): 1.430000 0.000000 1.430000 ( 1.425103)
|
104
|
+
translate(4): 1.500000 0.010000 1.510000 ( 1.500952)
|
106
105
|
|
107
106
|
## OK, so what's the catch?
|
108
107
|
|
data/lib/i18nema.rb
CHANGED
@@ -4,20 +4,7 @@ require File.dirname(__FILE__) + '/i18nema/core_ext/hash'
|
|
4
4
|
require File.dirname(__FILE__) + '/i18nema/i18nema'
|
5
5
|
|
6
6
|
module I18nema
|
7
|
-
|
8
|
-
include I18n::Backend::Base
|
9
|
-
|
10
|
-
def store_translations(locale, data, options = {})
|
11
|
-
# TODO: make this moar awesome
|
12
|
-
@initialized = true
|
13
|
-
load_yml_string({locale => data}.deep_stringify_keys.to_yaml)
|
14
|
-
end
|
15
|
-
|
16
|
-
def init_translations
|
17
|
-
load_translations
|
18
|
-
@initialized = true
|
19
|
-
end
|
20
|
-
|
7
|
+
module CoreMethods
|
21
8
|
RESERVED_KEY_MAP = Hash[I18n::RESERVED_KEYS.map{|k|[k,true]}]
|
22
9
|
|
23
10
|
def translate(locale, key, options = {})
|
@@ -41,6 +28,22 @@ module I18nema
|
|
41
28
|
entry = interpolate(locale, entry, values) if values
|
42
29
|
entry
|
43
30
|
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Backend
|
34
|
+
include I18n::Backend::Base
|
35
|
+
include CoreMethods # defined in a module so that other modules (e.g. I18n::Backend::Fallbacks) can override them
|
36
|
+
|
37
|
+
def store_translations(locale, data, options = {})
|
38
|
+
# TODO: make this moar awesome
|
39
|
+
@initialized = true
|
40
|
+
load_yml_string({locale => data}.deep_stringify_keys.to_yaml)
|
41
|
+
end
|
42
|
+
|
43
|
+
def init_translations
|
44
|
+
load_translations
|
45
|
+
@initialized = true
|
46
|
+
end
|
44
47
|
|
45
48
|
protected
|
46
49
|
def load_file(filename)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: i18nema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: i18n
|