fast_gettext 0.8.1 → 0.9.0
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.
- checksums.yaml +4 -4
- data/lib/fast_gettext/cache.rb +42 -0
- data/lib/fast_gettext/storage.rb +28 -55
- data/lib/fast_gettext/version.rb +1 -1
- metadata +105 -73
- data/.gitignore +0 -2
- data/.travis.yml +0 -17
- data/Appraisals +0 -8
- data/CHANGELOG +0 -8
- data/Gemfile +0 -10
- data/Gemfile.lock +0 -52
- data/Rakefile +0 -25
- data/Readme.md +0 -261
- data/benchmark/base.rb +0 -46
- data/benchmark/baseline.rb +0 -5
- data/benchmark/fast_gettext.rb +0 -18
- data/benchmark/i18n_simple.rb +0 -8
- data/benchmark/ideal.rb +0 -24
- data/benchmark/locale/de.yml +0 -126
- data/benchmark/locale/de/LC_MESSAGES/large.mo +0 -0
- data/benchmark/misc/threadsave.rb +0 -21
- data/benchmark/namespace/fast_gettext.rb +0 -15
- data/benchmark/namespace/original.rb +0 -14
- data/benchmark/original.rb +0 -22
- data/examples/db/migration.rb +0 -22
- data/examples/missing_translation_logger.rb +0 -13
- data/fast_gettext.gemspec +0 -12
- data/gemfiles/rails23.gemfile +0 -14
- data/gemfiles/rails23.gemfile.lock +0 -56
- data/gemfiles/rails32.gemfile +0 -14
- data/gemfiles/rails32.gemfile.lock +0 -112
- data/gemfiles/rails40.gemfile +0 -15
- data/gemfiles/rails40.gemfile.lock +0 -110
- data/spec/aa_unconfigued_spec.rb +0 -21
- data/spec/cases/fake_load_path/iconv.rb +0 -2
- data/spec/cases/iconv_fallback.rb +0 -22
- data/spec/cases/interpolate_i18n_after_fast_gettext.rb +0 -7
- data/spec/cases/interpolate_i18n_before_fast_gettext.rb +0 -9
- data/spec/cases/safe_mode_can_handle_locales.rb +0 -5
- data/spec/fast_gettext/mo_file_spec.rb +0 -35
- data/spec/fast_gettext/po_file_spec.rb +0 -35
- data/spec/fast_gettext/storage_spec.rb +0 -386
- data/spec/fast_gettext/translation_repository/base_spec.rb +0 -24
- data/spec/fast_gettext/translation_repository/chain_spec.rb +0 -98
- data/spec/fast_gettext/translation_repository/db_spec.rb +0 -114
- data/spec/fast_gettext/translation_repository/logger_spec.rb +0 -40
- data/spec/fast_gettext/translation_repository/mo_spec.rb +0 -58
- data/spec/fast_gettext/translation_repository/po_spec.rb +0 -65
- data/spec/fast_gettext/translation_repository/yaml_spec.rb +0 -84
- data/spec/fast_gettext/translation_repository_spec.rb +0 -33
- data/spec/fast_gettext/translation_spec.rb +0 -363
- data/spec/fast_gettext/vendor/iconv_spec.rb +0 -7
- data/spec/fast_gettext/vendor/string_spec.rb +0 -101
- data/spec/fast_gettext_spec.rb +0 -51
- data/spec/fuzzy_locale/de/test.po +0 -22
- data/spec/locale/de/LC_MESSAGES/test.mo +0 -0
- data/spec/locale/de/LC_MESSAGES/test2.mo +0 -0
- data/spec/locale/de/test.po +0 -74
- data/spec/locale/de/test2.po +0 -64
- data/spec/locale/en/LC_MESSAGES/plural_test.mo +0 -0
- data/spec/locale/en/LC_MESSAGES/test.mo +0 -0
- data/spec/locale/en/plural_test.po +0 -20
- data/spec/locale/en/test.po +0 -59
- data/spec/locale/gsw_CH/LC_MESSAGES/test.mo +0 -0
- data/spec/locale/gsw_CH/test.po +0 -61
- data/spec/locale/yaml/de.yml +0 -25
- data/spec/locale/yaml/de2.yml +0 -25
- data/spec/locale/yaml/en.yml +0 -21
- data/spec/locale/yaml/notfound.yml +0 -2
- data/spec/obsolete_locale/de/test.po +0 -21
- data/spec/spec_helper.rb +0 -42
- data/spec/support/be_accessible_matcher.rb +0 -8
data/Appraisals
DELETED
data/CHANGELOG
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
0.7.0 -- set_locale resets to default locale if none of the available locales was tried to set
|
2
|
-
0.6.0 -- plurals use singular translations as fallack e.g. you translated 'Axis' then n_('Axis','Axis',1) would return the translation for 'Axis' if no plural translation was found
|
3
|
-
0.4.14 -- "" is translated as "", not as gettext meta information
|
4
|
-
0.4.0 -- pluralisation_rules is no longer stored in each repository, only retrived. Added Chain and Logger repository.
|
5
|
-
0.3.6 -- FastGettext.default_locale=
|
6
|
-
0.3.5 -- FastGettext.default_text_domain=
|
7
|
-
0.3.4 -- Exceptions are thrown, not returned when translating without text domain
|
8
|
-
0.3 -- pluralisation methods accept/return n plural forms, contrary to singular/plural before
|
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
fast_gettext (0.8.1)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
activemodel (3.2.14)
|
10
|
-
activesupport (= 3.2.14)
|
11
|
-
builder (~> 3.0.0)
|
12
|
-
activerecord (3.2.14)
|
13
|
-
activemodel (= 3.2.14)
|
14
|
-
activesupport (= 3.2.14)
|
15
|
-
arel (~> 3.0.2)
|
16
|
-
tzinfo (~> 0.3.29)
|
17
|
-
activesupport (3.2.14)
|
18
|
-
i18n (~> 0.6, >= 0.6.4)
|
19
|
-
multi_json (~> 1.0)
|
20
|
-
appraisal (0.5.2)
|
21
|
-
bundler
|
22
|
-
rake
|
23
|
-
arel (3.0.2)
|
24
|
-
builder (3.0.4)
|
25
|
-
bump (0.4.2)
|
26
|
-
diff-lcs (1.2.4)
|
27
|
-
i18n (0.6.5)
|
28
|
-
multi_json (1.7.9)
|
29
|
-
rake (10.1.0)
|
30
|
-
rspec (2.14.1)
|
31
|
-
rspec-core (~> 2.14.0)
|
32
|
-
rspec-expectations (~> 2.14.0)
|
33
|
-
rspec-mocks (~> 2.14.0)
|
34
|
-
rspec-core (2.14.5)
|
35
|
-
rspec-expectations (2.14.2)
|
36
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
37
|
-
rspec-mocks (2.14.3)
|
38
|
-
sqlite3 (1.3.8)
|
39
|
-
tzinfo (0.3.37)
|
40
|
-
|
41
|
-
PLATFORMS
|
42
|
-
ruby
|
43
|
-
|
44
|
-
DEPENDENCIES
|
45
|
-
activerecord
|
46
|
-
appraisal
|
47
|
-
bump
|
48
|
-
fast_gettext!
|
49
|
-
i18n
|
50
|
-
rake
|
51
|
-
rspec
|
52
|
-
sqlite3
|
data/Rakefile
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'bundler/setup'
|
2
|
-
require 'bundler/gem_tasks'
|
3
|
-
require 'bump/tasks'
|
4
|
-
require 'appraisal'
|
5
|
-
|
6
|
-
task :default do
|
7
|
-
sh "rake appraisal:install && rake appraisal spec"
|
8
|
-
end
|
9
|
-
|
10
|
-
task :spec do
|
11
|
-
sh "rspec spec"
|
12
|
-
end
|
13
|
-
|
14
|
-
task :benchmark do
|
15
|
-
puts "Running on #{RUBY_DESCRIPTION}"
|
16
|
-
%w[baseline ideal fast_gettext original i18n_simple].each do |bench|
|
17
|
-
puts `ruby -I. benchmark/#{bench}.rb`
|
18
|
-
puts ""
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
task :namespaces do
|
23
|
-
puts `ruby benchmark/namespace/original.rb`
|
24
|
-
puts `ruby benchmark/namespace/fast_gettext.rb`
|
25
|
-
end
|
data/Readme.md
DELETED
@@ -1,261 +0,0 @@
|
|
1
|
-
FastGettext
|
2
|
-
===========
|
3
|
-
GetText but 3.5 x faster, 560 x less memory, simple, clean namespace (7 vs 34) and threadsafe!
|
4
|
-
|
5
|
-
It supports multiple backends (.mo, .po, .yml files, Database(ActiveRecord + any other), Chain, Loggers) and can easily be extended.
|
6
|
-
|
7
|
-
[Example Rails application](https://github.com/grosser/gettext_i18n_rails_example)
|
8
|
-
|
9
|
-
Comparison
|
10
|
-
==========
|
11
|
-
<table>
|
12
|
-
<tr>
|
13
|
-
<td></td>
|
14
|
-
<td width="100">Hash</td>
|
15
|
-
<td width="150">FastGettext</td>
|
16
|
-
<td width="100">GetText</td>
|
17
|
-
<td width="100">ActiveSupport I18n::Simple</td>
|
18
|
-
</tr>
|
19
|
-
<tr>
|
20
|
-
<td>Speed*</td>
|
21
|
-
<td>0.82s</td>
|
22
|
-
<td>1.36s</td>
|
23
|
-
<td>4.88s</td>
|
24
|
-
<td>21.77s</td>
|
25
|
-
</tr>
|
26
|
-
<tr>
|
27
|
-
<td>RAM*</td>
|
28
|
-
<td>4K</td>
|
29
|
-
<td>8K</td>
|
30
|
-
<td>4480K</td>
|
31
|
-
<td>10100K</td>
|
32
|
-
</tr>
|
33
|
-
<tr>
|
34
|
-
<td>Included backends</td>
|
35
|
-
<td></td>
|
36
|
-
<td>db, yml, mo, po, logger, chain</td>
|
37
|
-
<td>mo</td>
|
38
|
-
<td>yml (db/key-value/po/chain in other I18n backends)</td>
|
39
|
-
</tr>
|
40
|
-
</table>
|
41
|
-
<small>*50.000 translations with ruby enterprise 1.8.6 through `rake benchmark`</small>
|
42
|
-
|
43
|
-
Setup
|
44
|
-
=====
|
45
|
-
### 1. Install
|
46
|
-
|
47
|
-
sudo gem install fast_gettext
|
48
|
-
|
49
|
-
### 2. Add a translation repository
|
50
|
-
|
51
|
-
From mo files (traditional/default)
|
52
|
-
|
53
|
-
FastGettext.add_text_domain('my_app',:path => 'locale')
|
54
|
-
|
55
|
-
Or po files (less maintenance than mo)
|
56
|
-
|
57
|
-
FastGettext.add_text_domain('my_app',:path => 'locale', :type => :po)
|
58
|
-
# :ignore_fuzzy => true to not use fuzzy translations
|
59
|
-
# :report_warning => false to hide warnings about obsolete/fuzzy translations
|
60
|
-
|
61
|
-
Or yaml files (use I18n syntax/indentation)
|
62
|
-
|
63
|
-
FastGettext.add_text_domain('my_app', :path => 'config/locales', :type => :yaml)
|
64
|
-
|
65
|
-
Or database (scaleable, good for many locales/translators)
|
66
|
-
|
67
|
-
# db access is cached <-> only first lookup hits the db
|
68
|
-
require "fast_gettext/translation_repository/db"
|
69
|
-
FastGettext::TranslationRepository::Db.require_models #load and include default models
|
70
|
-
FastGettext.add_text_domain('my_app', :type => :db, :model => TranslationKey)
|
71
|
-
|
72
|
-
### 3. Choose text domain and locale for translation
|
73
|
-
Do this once in every Thread. (e.g. Rails -> ApplicationController)
|
74
|
-
|
75
|
-
FastGettext.text_domain = 'my_app'
|
76
|
-
FastGettext.available_locales = ['de','en','fr','en_US','en_UK'] # only allow these locales to be set (optional)
|
77
|
-
FastGettext.locale = 'de'
|
78
|
-
|
79
|
-
### 4. Start translating
|
80
|
-
|
81
|
-
include FastGettext::Translation
|
82
|
-
_('Car') == 'Auto'
|
83
|
-
_('not-found') == 'not-found'
|
84
|
-
s_('Namespace|no-found') == 'not-found'
|
85
|
-
n_('Axis','Axis',3) == 'Achsen' #German plural of Axis
|
86
|
-
_('Hello %{name}!') % {:name => "Pete"} == 'Hello Pete!'
|
87
|
-
|
88
|
-
|
89
|
-
Managing translations
|
90
|
-
============
|
91
|
-
### mo/po-files
|
92
|
-
Generate .po or .mo files using GetText parser (example tasks at [gettext_i18n_rails](http://github.com/grosser/gettext_i18n_rails))
|
93
|
-
|
94
|
-
Tell Gettext where your .mo or .po files lie, e.g. for locale/de/my_app.po and locale/de/LC_MESSAGES/my_app.mo
|
95
|
-
|
96
|
-
FastGettext.add_text_domain('my_app',:path=>'locale')
|
97
|
-
|
98
|
-
Use the [original GetText](http://github.com/mutoh/gettext) to create and manage po/mo-files.
|
99
|
-
(Work on a po/mo parser & reader that is easier to use has started, contributions welcome @ [get_pomo](http://github.com/grosser/get_pomo) )
|
100
|
-
|
101
|
-
###Database
|
102
|
-
[Example migration for ActiveRecord](http://github.com/grosser/fast_gettext/blob/master/examples/db/migration.rb)<br/>
|
103
|
-
The default plural seperator is `||||` but you may overwrite it (or suggest a better one..).
|
104
|
-
|
105
|
-
This is usable with any model DataMapper/Sequel or any other(non-database) backend, the only thing you need to do is respond to the self.translation(key, locale) call.
|
106
|
-
If you want to use your own models, have a look at the [default models](http://github.com/grosser/fast_gettext/tree/master/lib/fast_gettext/translation_repository/db_models) to see what you want/need to implement.
|
107
|
-
|
108
|
-
To manage translations via a Web GUI, use a [Rails application and the translation_db_engine](http://github.com/grosser/translation_db_engine)
|
109
|
-
|
110
|
-
Rails
|
111
|
-
=======================
|
112
|
-
Try the [gettext_i18n_rails plugin](http://github.com/grosser/gettext_i18n_rails), it simplifies the setup.<br/>
|
113
|
-
Try the [translation_db_engine](http://github.com/grosser/translation_db_engine), to manage your translations in a db.
|
114
|
-
|
115
|
-
Setting `available_locales`,`text_domain` or `locale` will not work inside the `evironment.rb`,
|
116
|
-
since it runs in a different thread then e.g. controllers, so set them inside your application_controller.
|
117
|
-
|
118
|
-
#environment.rb after initializers
|
119
|
-
Object.send(:include,FastGettext::Translation)
|
120
|
-
FastGettext.add_text_domain('accounting',:path=>'locale')
|
121
|
-
FastGettext.add_text_domain('frontend',:path=>'locale')
|
122
|
-
...
|
123
|
-
|
124
|
-
#application_controller.rb
|
125
|
-
class ApplicationController ...
|
126
|
-
include FastGettext::Translation
|
127
|
-
before_filter :set_locale
|
128
|
-
def set_locale
|
129
|
-
FastGettext.available_locales = ['de','en',...]
|
130
|
-
FastGettext.text_domain = 'frontend'
|
131
|
-
FastGettext.set_locale(params[:locale] || session[:locale] || request.env['HTTP_ACCEPT_LANGUAGE'])
|
132
|
-
session[:locale] = I18n.locale = FastGettext.locale
|
133
|
-
end
|
134
|
-
|
135
|
-
|
136
|
-
Advanced features
|
137
|
-
=================
|
138
|
-
### Abnormal pluralisation
|
139
|
-
Plurals are selected by index, think of it as `['car', 'cars'][index]`<br/>
|
140
|
-
A pluralisation rule decides which form to use e.g. in english its `count == 1 ? 0 : 1`.<br/>
|
141
|
-
If you have any languages that do not fit this rule, you have to add a custom pluralisation rule.
|
142
|
-
|
143
|
-
Via Ruby:
|
144
|
-
|
145
|
-
FastGettext.pluralisation_rule = lamda{|count| count > 5 ? 1 : (count > 2 ? 0 : 2)}
|
146
|
-
|
147
|
-
Via mo/pofile:
|
148
|
-
|
149
|
-
Plural-Forms: nplurals=2; plural=n==2?3:4;
|
150
|
-
|
151
|
-
[Plural expressions for all languages](http://translate.sourceforge.net/wiki/l10n/pluralforms).
|
152
|
-
|
153
|
-
###default_text_domain
|
154
|
-
If you only use one text domain, setting `FastGettext.default_text_domain = 'app'`
|
155
|
-
is sufficient and no more `text_domain=` is needed
|
156
|
-
|
157
|
-
###default_locale
|
158
|
-
If the simple rule of "first `availble_locale` or 'en'" is not suficcient for you, set `FastGettext.default_locale = 'de'`.
|
159
|
-
|
160
|
-
###default_available_locales
|
161
|
-
Fallback when no available_locales are set
|
162
|
-
|
163
|
-
###Chains
|
164
|
-
You can use any number of repositories to find a translation. Simply add them to a chain and when
|
165
|
-
the first cannot translate a given key, the next is asked and so forth.
|
166
|
-
|
167
|
-
repos = [
|
168
|
-
FastGettext::TranslationRepository.build('new', :path=>'....'),
|
169
|
-
FastGettext::TranslationRepository.build('old', :path=>'....')
|
170
|
-
]
|
171
|
-
FastGettext.add_text_domain 'combined', :type=>:chain, :chain=>repos
|
172
|
-
|
173
|
-
###Logger
|
174
|
-
When you want to know which keys could not be translated or were used, add a Logger to a Chain:
|
175
|
-
|
176
|
-
repos = [
|
177
|
-
FastGettext::TranslationRepository.build('app', :path=>'....')
|
178
|
-
FastGettext::TranslationRepository.build('logger', :type=>:logger, :callback=>lamda{|key_or_array_of_ids| ... }),
|
179
|
-
}
|
180
|
-
FastGettext.add_text_domain 'combined', :type=>:chain, :chain=>repos
|
181
|
-
|
182
|
-
If the Logger is in position #1 it will see all translations, if it is in position #2 it will only see the unfound.
|
183
|
-
Unfound may not always mean missing, if you choose not to translate a word because the key is a good translation, it will appear nevertheless.
|
184
|
-
A lambda or anything that responds to `call` will do as callback. A good starting point may be `examples/missing_translations_logger.rb`.
|
185
|
-
|
186
|
-
###Plugins
|
187
|
-
Want a xml version ?
|
188
|
-
Write your own TranslationRepository!
|
189
|
-
|
190
|
-
#fast_gettext/translation_repository/xxx.rb
|
191
|
-
module FastGettext
|
192
|
-
module TranslationRepository
|
193
|
-
class Wtf
|
194
|
-
define initialize(name,options), [key], plural(*keys) and
|
195
|
-
either inherit from TranslationRepository::Base or define available_locales and pluralisation_rule
|
196
|
-
end
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
###Multi domain support
|
201
|
-
|
202
|
-
If you have more than one gettext domain, there are two sets of functions
|
203
|
-
available:
|
204
|
-
|
205
|
-
include FastGettext::TranslationMultidomain
|
206
|
-
|
207
|
-
d_("domainname", "string") # finds 'string' in domain domainname
|
208
|
-
dn_("domainname", "string", "strings", 1) # ditto
|
209
|
-
# etc.
|
210
|
-
|
211
|
-
These are helper methods so you don't need to write:
|
212
|
-
|
213
|
-
FastGettext.text_domain = "domainname"
|
214
|
-
_("string")
|
215
|
-
|
216
|
-
It is useful in Rails plugins in the views for example. The second set of
|
217
|
-
functions are D functions which search for string in _all_ domains. If there
|
218
|
-
are multiple translations in different domains, it returns them in random
|
219
|
-
order (depends on the Ruby hash implementation):
|
220
|
-
|
221
|
-
include FastGettext::TranslationMultidomain
|
222
|
-
|
223
|
-
D_("string") # finds 'string' in any domain
|
224
|
-
# etc.
|
225
|
-
|
226
|
-
FAQ
|
227
|
-
===
|
228
|
-
- [Problems with ActiveRecord messages?](http://wiki.github.com/grosser/fast_gettext/activerecord)
|
229
|
-
- [Iconv require error in 1.9.2](http://exceptionz.wordpress.com/2010/02/03/how-to-fix-the-iconv-require-error-in-ruby-1-9)
|
230
|
-
|
231
|
-
|
232
|
-
TODO
|
233
|
-
====
|
234
|
-
- Add a fallback for Iconv.conv in ruby 1.9.4 -> lib/fast_gettext/vendor/iconv
|
235
|
-
- YML backend that reads ActiveSupport::I18n files
|
236
|
-
|
237
|
-
Author
|
238
|
-
======
|
239
|
-
Mo/Po-file parsing from Masao Mutoh, see vendor/README
|
240
|
-
|
241
|
-
### [Contributors](http://github.com/grosser/fast_gettext/contributors)
|
242
|
-
- [geekq](http://www.innoq.com/blog/vd)
|
243
|
-
- [Matt Sanford](http://blog.mzsanford.com)
|
244
|
-
- [Antonio Terceiro](http://softwarelivre.org/terceiro)
|
245
|
-
- [J. Pablo Fernández](http://pupeno.com)
|
246
|
-
- Rudolf Gavlas
|
247
|
-
- [Ramón Cahenzli](http://www.psy-q.ch)
|
248
|
-
- [Rainux Luo](http://rainux.org)
|
249
|
-
- [Dmitry Borodaenko](https://github.com/angdraug)
|
250
|
-
- [Kouhei Sutou](https://github.com/kou)
|
251
|
-
- [Hoang Nghiem](https://github.com/hoangnghiem)
|
252
|
-
- [Costa Shapiro](https://github.com/costa)
|
253
|
-
- [Jamie Dyer](https://github.com/kernow)
|
254
|
-
- [Stephan Kulow](https://github.com/coolo)
|
255
|
-
- [Fotos Georgiadis](https://github.com/fotos)
|
256
|
-
- [Lukáš Zapletal](https://github.com/lzap)
|
257
|
-
|
258
|
-
[Michael Grosser](http://grosser.it)<br/>
|
259
|
-
michael@grosser.it<br/>
|
260
|
-
License: MIT, some vendor parts under the same license terms as Ruby (see headers)<br/>
|
261
|
-
[](https://travis-ci.org/grosser/fast_gettext)
|
data/benchmark/base.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'benchmark'
|
3
|
-
|
4
|
-
RUNS = 50_0000
|
5
|
-
DEFAULTS = {:memory=>0}
|
6
|
-
|
7
|
-
def locale_folder(domain)
|
8
|
-
path = case domain
|
9
|
-
when 'test' then File.join(File.expand_path(File.dirname(__FILE__)),'..','spec','locale')
|
10
|
-
when 'large' then File.join(File.expand_path(File.dirname(__FILE__)),'locale')
|
11
|
-
end
|
12
|
-
|
13
|
-
mo = File.join(path,'de','LC_MESSAGES',"#{domain}.mo")
|
14
|
-
raise unless File.exist?(mo)
|
15
|
-
path
|
16
|
-
end
|
17
|
-
|
18
|
-
def results_test(&block)
|
19
|
-
print "#{(result(&block)).to_s.strip.split(' ').first}s / #{memory}K <-> "
|
20
|
-
end
|
21
|
-
|
22
|
-
def results_large
|
23
|
-
print "#{(result {_('login') == 'anmelden'}).to_s.strip.split(' ').first}s / #{memory}K"
|
24
|
-
puts ""
|
25
|
-
end
|
26
|
-
|
27
|
-
def result
|
28
|
-
result =Benchmark.measure do
|
29
|
-
RUNS.times do
|
30
|
-
raise "not translated" unless yield
|
31
|
-
end
|
32
|
-
end
|
33
|
-
result
|
34
|
-
end
|
35
|
-
|
36
|
-
def memory
|
37
|
-
pid = Process.pid
|
38
|
-
if RUBY_PLATFORM.downcase.include?("darwin")
|
39
|
-
map = `vmmap #{pid}`
|
40
|
-
else
|
41
|
-
map = `pmap -d #{pid}`
|
42
|
-
end
|
43
|
-
map.split("\n").last.strip.squeeze(' ').split(' ')[3].to_i - DEFAULTS[:memory]
|
44
|
-
end
|
45
|
-
|
46
|
-
DEFAULTS[:memory] = memory + 4 #4 => 0 for base calls
|
data/benchmark/baseline.rb
DELETED
data/benchmark/fast_gettext.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'benchmark/base'
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift 'lib'
|
4
|
-
require 'fast_gettext'
|
5
|
-
include FastGettext::Translation
|
6
|
-
|
7
|
-
FastGettext.available_locales = ['de','en']
|
8
|
-
FastGettext.locale = 'de'
|
9
|
-
|
10
|
-
puts "FastGettext:"
|
11
|
-
FastGettext.add_text_domain('test',:path=>locale_folder('test'))
|
12
|
-
FastGettext.text_domain = 'test'
|
13
|
-
results_test{_('car') == 'Auto'}
|
14
|
-
|
15
|
-
#i cannot add the large file, since its an internal applications mo file
|
16
|
-
FastGettext.add_text_domain('large',:path=>locale_folder('large'))
|
17
|
-
FastGettext.text_domain = 'large'
|
18
|
-
results_large
|