Skip to content

brynary/i18n

 
 

Repository files navigation

Ruby I18n

Ruby Internationalization and localization solution.

Features:

  • translation and localization
  • interpolation of values to translations (Ruby 1.9 compatible syntax)
  • pluralization (CLDR compatible)
  • flexible defaults
  • bulk lookup
  • lambdas as translation data
  • custom key/scope separator
  • custom exception handlers
  • extensible architecture with a swappable backend

Experimental, pluggable features:

  • lambda pluralizers stored as translation data
  • RFC4647 compliant locale fallbacks (with optional RFC4646 locale validation)
  • backend cache

For more information and lots of resources see: http://rails-i18n.org/wiki

Fast backend

This fork includes a Fast backend that optimizes for the most common lookups and makes them faster than the original Simple backend. The Fast backend is slightly less memory efficient and is slower to reload!, but should be a great choice for production environment.

Here’s the output of the included benchamrk (the source can be found in `benchmark/bench.rb`):

Ruby 1.8.6:


  $ ruby bench.rb 
  Rehearsal ----------------------------------------------------------------------------
  s.t(:'foo.bar.bax.buz')                   12.560000   0.100000  12.660000 ( 14.118697)
  f.t(:'foo.bar.bax.buz')                    1.210000   0.010000   1.220000 (  1.420918)
  s.t(:'foo.bar.tr', :a => 'A', :b => 'B')  21.270000   0.170000  21.440000 ( 23.812063)
  f.t(:'foo.bar.tr', :a => 'A', :b => 'B')   3.090000   0.020000   3.110000 (  3.474864)
  ------------------------------------------------------------------ total: 38.430000sec

                                                 user     system      total        real
  s.t(:'foo.bar.bax.buz')                   12.600000   0.100000  12.700000 ( 14.140978)
  f.t(:'foo.bar.bax.buz')                    1.210000   0.010000   1.220000 (  1.308616)
  s.t(:'foo.bar.tr', :a => 'A', :b => 'B')  21.270000   0.170000  21.440000 ( 24.077774)
  f.t(:'foo.bar.tr', :a => 'A', :b => 'B')   3.060000   0.020000   3.080000 (  3.429054)

Ruby 1.9.1:


  $ /usr/local/ruby1.9/bin/ruby bench.rb 
  Rehearsal ----------------------------------------------------------------------------
  s.t(:'foo.bar.bax.buz')                    6.800000   0.070000   6.870000 (  7.680139)
  f.t(:'foo.bar.bax.buz')                    0.520000   0.000000   0.520000 (  0.561464)
  s.t(:'foo.bar.tr', :a => 'A', :b => 'B')  12.890000   0.130000  13.020000 ( 14.533934)
  f.t(:'foo.bar.tr', :a => 'A', :b => 'B')   1.930000   0.020000   1.950000 (  2.132250)
  ------------------------------------------------------------------ total: 22.360000sec

                                                 user     system      total        real
  s.t(:'foo.bar.bax.buz')                    6.800000   0.070000   6.870000 (  7.659024)
  f.t(:'foo.bar.bax.buz')                    0.510000   0.000000   0.510000 (  0.560259)
  s.t(:'foo.bar.tr', :a => 'A', :b => 'B')  12.890000   0.130000  13.020000 ( 14.491398)
  f.t(:'foo.bar.tr', :a => 'A', :b => 'B')   1.940000   0.020000   1.960000 (  2.127320)

Branches

2-3-stable branch is for the old I18n gem shipped with Rails 2.3
master is for the current I18n gem version

Usage

Clone the repo as a plugin into your Rails app.

  # in initializer or enviroment.rb
  I18n.backend = I18n::Backend::Fast.new

Slower development mode and LazyReloading

Fast backend is at least a few times slower to reload! than the Simple backend and since Rails auto-reloads translation files on each request while in development mode using Fast backend in dev mode might slow you down.

LazyReloading extension tries to mitigate the issue by first checking mtimes of the translation files before reloading them. It is also helpful even if you are running on Simple backend and have a big application with huge translation files.

Using LazyReloading:

  # in initializer or enviroment.rb
  I18n::Backend::Base.send(:include, I18n::Backend::LazyReloading)

Authors

License

MIT License. See the included MIT-LICENCE file.

About

Experimenting with a faster backend

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages