grosser-fast_gettext 0.4.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +16 -15
- data/VERSION.yml +1 -1
- data/lib/fast_gettext/mo_file.rb +4 -2
- data/spec/vendor/string_spec.rb +25 -2
- data/vendor/string.rb +15 -4
- metadata +2 -2
data/README.markdown
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
FastGettext
|
2
2
|
===========
|
3
|
-
GetText but
|
3
|
+
GetText but 3.5 x faster, 20 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.240000s / 1196K <->
|
43
43
|
|
44
44
|
Ideal: (primitive Hash lookup)
|
45
|
-
|
45
|
+
0.790000s / 1200K <-> 0.760000s / 1200K
|
46
46
|
|
47
47
|
FastGettext:
|
48
|
-
1.
|
48
|
+
1.360000s / 1200K <-> 1.340000s / 1200K
|
49
49
|
|
50
|
-
GetText 2.0:
|
51
|
-
|
50
|
+
GetText 2.0.1:
|
51
|
+
4.810000s / 6.176K <-> 4.770000s / 6.176K
|
52
52
|
|
53
53
|
ActiveSupport I18n::Backend::Simple :
|
54
|
-
|
54
|
+
21.800000s / 11296K <->
|
55
|
+
|
55
56
|
|
56
57
|
|
57
58
|
|
@@ -95,7 +96,7 @@ I already started work on a po/mo parser & reader that is easier to use, contrib
|
|
95
96
|
Advanced features
|
96
97
|
=================
|
97
98
|
###Abnormal pluralisation
|
98
|
-
Pluralisation rules can be set directly via a lambda (see
|
99
|
+
Pluralisation rules can be set directly via a lambda (see specs/), or by using the Gettext
|
99
100
|
plural definition (see spec/locale/en/test_plural.po or [Plural expressions for all languages](http://translate.sourceforge.net/wiki/l10n/pluralforms).
|
100
101
|
|
101
102
|
###default_text_domain
|
@@ -107,15 +108,15 @@ If the simple rule of "first `availble_locale` or 'en'" is not suficcient for yo
|
|
107
108
|
|
108
109
|
###Chains
|
109
110
|
You can use any number of repositories to find a translation. Simply add them to a chain and when
|
110
|
-
the first cannot translate a given
|
111
|
+
the first cannot translate a given msgid, the next is asked and so forth.
|
111
112
|
repos = [
|
112
|
-
FastGettext::TranslationRepository.build('
|
113
|
-
FastGettext::TranslationRepository.build('
|
113
|
+
FastGettext::TranslationRepository.build('new', :path=>'....'),
|
114
|
+
FastGettext::TranslationRepository.build('old', :path=>'....')
|
114
115
|
]
|
115
116
|
FastGettext.add_text_domain 'combined', :type=>:chain, :chain=>repos
|
116
117
|
|
117
|
-
|
118
|
-
When you want to know which keys could not be translated
|
118
|
+
###Logger
|
119
|
+
When you want to know which keys could not be translated or were used, add a Logger to a Chain:
|
119
120
|
repos = [
|
120
121
|
FastGettext::TranslationRepository.build('app', :path=>'....')
|
121
122
|
FastGettext::TranslationRepository.build('logger', :type=>:logger, :callback=>lamda{|msgid_or_array_of_ids| ... }),
|
@@ -123,7 +124,7 @@ When you want to know which keys could not be translated, or where used, add a L
|
|
123
124
|
FastGettext.add_text_domain 'combined', :type=>:chain, :chain=>repos
|
124
125
|
If the Logger is in position #1 it will see all translations, if it is in position #2 it will only see the unfound.
|
125
126
|
Unfound may not always mean missing, if you chose not to translate a word because the msgid is a good translation, it will appear nevertheless.
|
126
|
-
A lambda or anything that responds to `call` will do as callback.
|
127
|
+
A lambda or anything that responds to `call` will do as callback. A good starting point may be `examples/missing_translations_logger.rb`.
|
127
128
|
|
128
129
|
###Plugins
|
129
130
|
Want a yml, xml, database version ?
|
@@ -133,7 +134,7 @@ Write your own TranslationRepository!
|
|
133
134
|
module TranslationRepository
|
134
135
|
class Wtf
|
135
136
|
define initialize(name,options), [key], plural(*msgids) and
|
136
|
-
either inherit from Base or define available_locales and
|
137
|
+
either inherit from TranslationRepository::Base or define available_locales and pluralisation_rule
|
137
138
|
end
|
138
139
|
end
|
139
140
|
end
|
data/VERSION.yml
CHANGED
data/lib/fast_gettext/mo_file.rb
CHANGED
@@ -43,13 +43,15 @@ module FastGettext
|
|
43
43
|
|
44
44
|
#(if plural==singular, prefer singular)
|
45
45
|
def make_singular_and_plural_available
|
46
|
+
data = {}
|
46
47
|
@data.each do |key,translation|
|
47
48
|
next unless key.include? PLURAL_SEPERATOR
|
48
49
|
singular, plural = split_plurals(key)
|
49
50
|
translation = split_plurals(translation)
|
50
|
-
|
51
|
-
|
51
|
+
data[singular] ||= translation[0]
|
52
|
+
data[plural] ||= translation[1]
|
52
53
|
end
|
54
|
+
@data.merge!(data){|key,old,new| old}
|
53
55
|
end
|
54
56
|
|
55
57
|
def split_plurals(singular_plural)
|
data/spec/vendor/string_spec.rb
CHANGED
@@ -6,7 +6,30 @@ describe String do
|
|
6
6
|
it "substitudes using % + Hash" do
|
7
7
|
"x%{name}y" %{:name=>'a'}.should == 'xay'
|
8
8
|
end
|
9
|
-
|
10
|
-
|
9
|
+
|
10
|
+
describe 'old sprintf style' do
|
11
|
+
it "substitudes using % + Array" do
|
12
|
+
("x%sy%s" % ['a','b']).should == 'xayb'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "does not remove %{} style replacements" do
|
16
|
+
("%{name} x%sy%s" % ['a','b']).should == '%{name} xayb'
|
17
|
+
end
|
18
|
+
|
19
|
+
it "does not remove %<> style replacement" do
|
20
|
+
("%{name} %<num>f %s" % ['x']).should == "%{name} %<num>f x"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'ruby 1.9 style %< replacement' do
|
25
|
+
it "subsitutes %<something>d" do
|
26
|
+
("x%<hello>dy" % {:hello=>1}).should == 'x1y'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "substitutes #b" do
|
30
|
+
("%<num>#b" % {:num => 1}).should == "0b1"
|
31
|
+
end
|
32
|
+
|
33
|
+
|
11
34
|
end
|
12
35
|
end
|
data/vendor/string.rb
CHANGED
@@ -19,17 +19,28 @@ rescue ArgumentError
|
|
19
19
|
# %(hash)
|
20
20
|
#
|
21
21
|
# Default: "%s, %s" % ["Masao", "Mutoh"]
|
22
|
-
# Extended:
|
23
|
-
#
|
22
|
+
# Extended:
|
23
|
+
# "%{firstname}, %{lastname}" % {:firstname=>"Masao",:lastname=>"Mutoh"} == "Masao Mutoh"
|
24
|
+
# with field type such as d(decimal), f(float), ...
|
25
|
+
# "%<age>d, %<weight>.1f" % {:age => 10, :weight => 43.4} == "10 43.4"
|
24
26
|
# This is the recommanded way for Ruby-GetText
|
25
27
|
# because the translators can understand the meanings of the msgids easily.
|
26
28
|
def %(args)
|
27
|
-
if args.kind_of?
|
29
|
+
if args.kind_of? Hash
|
28
30
|
ret = dup
|
31
|
+
# %{something} type
|
29
32
|
args.each {|key, value| ret.gsub!(/\%\{#{key}\}/, value.to_s)}
|
33
|
+
|
34
|
+
# %<..>d type
|
35
|
+
args.each {|key, value|
|
36
|
+
ret.gsub!(/\%<#{key}>([ #\+-0\*]?\d*\.?\d*[bBdiouxXeEfgGcps])/){
|
37
|
+
sprintf("%#{$1}", value)
|
38
|
+
}
|
39
|
+
}
|
40
|
+
ret.gsub(/%%/, "%")
|
30
41
|
ret
|
31
42
|
else
|
32
|
-
ret = gsub(
|
43
|
+
ret = gsub(/%([{<])/, '%%\1')
|
33
44
|
ret._fast_gettext_old_format_m(args)
|
34
45
|
end
|
35
46
|
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.4.
|
4
|
+
version: 0.4.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-04-
|
12
|
+
date: 2009-04-22 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|