README.markdown in grosser-fast_gettext-0.4.2 vs README.markdown in grosser-fast_gettext-0.4.3

- old
+ new

@@ -1,26 +1,21 @@ FastGettext =========== -GetText but 3.5 x faster, 20 x less memory, simple, clean namespace (7 vs 34) and threadsave! +GetText but 3.5 x faster, 560 x less memory, simple, clean namespace (7 vs 34) and threadsave! +It supports multiple backends (atm: .mo files, .po files, ActiveRecord, Chain) and can easily be extended. + [Example Rails application](https://github.com/grosser/gettext_i18n_rails_example) Setup ===== sudo gem install grosser-fast_gettext -s http://gems.github.com/ Or from source: git clone git://github.com/grosser/fast_gettext.git cd fast_gettext && rake install -Generate .po or .mo files using GetText parser (example tasks at [gettext_i18n_rails](http://github.com/grosser/gettext_i18n_rails)) - -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 - #add :type=>:po and it will read directly from po files (not recommended for production since po-parsing can crash!) - FastGettext.add_text_domain('my_app',:path=>'locale') - Choose text domain and locale for translation FastGettext.text_domain = 'my_app' FastGettext.available_locales = ['de','en','fr','en_US','en_UK'] # only allow these locales to be set (optional) FastGettext.locale = 'de' @@ -32,33 +27,55 @@ n_('Axis','Axis',3) == 'Achsen' #German plural of Axis Disable translation errors(like no text domain setup) while doing e.g. console session / testing FastGettext.silence_errors +Translations +============ +### Default: .mo-files +Generate .po or .mo files using GetText parser (example tasks at [gettext_i18n_rails](http://github.com/grosser/gettext_i18n_rails)) + +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 + #add :type=>:po and it will read directly from po files (not recommended for production since po-parsing can crash!) + FastGettext.add_text_domain('my_app',:path=>'locale') + +ATM you have to use the [original GetText](http://github.com/mutoh/gettext) to create and manage your po/mo-files. +I already started work on a po/mo parser & reader that is easier to use, contributions welcome @ [pomo](http://github.com/grosser/pomo) + +###Database +!!!This is very new/alpha-ish atm and surely will change!!! +Eesy to maintain especially with many translations and multiple locales. +ATM the default implementation is a bit clumsy, it is build so that the model can be substituted by your own. + FastGettext.add_text_domain('my_app', :type=>:db, :model=>TranslationKey) + #the model should be the model that represents the keys, you can use FastGettext::TranslationRepository::DB::TranslationKey + #the model must have string:key and translations + #a Translation must have string:text and string:locale + +To get started have a look at the tests in `spec/fast_gettext/translation_repository/db_spec.rb`(includes migrations) or the models +in `lib/fast_gettext/translation_repository/db/translation_key`. + Performance =========== -50_000 translations speed / memory -small translation file <-> large translation file +50_000 translations speed / memory +small translation file <-> large translation file +(ruby enterprise 1.8.6, your results may vary, try `rake benchmark`) Baseline: (doing nothing in a loop) - 0.240000s / 1196K <-> + 0.250000s / 0K <-> Ideal: (primitive Hash lookup) - 0.790000s / 1200K <-> 0.760000s / 1200K + 0.820000s / 4K <-> 0.760000s / 4K FastGettext: - 1.360000s / 1200K <-> 1.340000s / 1200K + 1.360000s / 8K <-> 1.320000s / 8K GetText 2.0.1: - 4.810000s / 6.176K <-> 4.770000s / 6.176K + 4.880000s / 4480K <-> 4.810000s / 4480K ActiveSupport I18n::Backend::Simple : - 21.800000s / 11296K <-> + 21.770000s / 10100K <-> - - - - Thread Safety and Rails ======================= Parsed `text_domains` are not stored thread-save, so that they can be added inside the `environment.rb`, and do not need to be readded for every thread (parsing takes time...). @@ -86,15 +103,10 @@ #application_helper.rb module ApplicationHelper include FastGettext::Translation ... -Updating translations -===================== -ATM you have to use the [original GetText](http://github.com/mutoh/gettext) to create and manage your po/mo-files. -I already started work on a po/mo parser & reader that is easier to use, contributions welcome @ [pomo](http://github.com/grosser/pomo) - Advanced features ================= ###Abnormal pluralisation Pluralisation rules can be set directly via a lambda (see specs/), or by using the Gettext plural definition (see spec/locale/en/test_plural.po or [Plural expressions for all languages](http://translate.sourceforge.net/wiki/l10n/pluralforms). @@ -125,11 +137,11 @@ If the Logger is in position #1 it will see all translations, if it is in position #2 it will only see the unfound. 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. A lambda or anything that responds to `call` will do as callback. A good starting point may be `examples/missing_translations_logger.rb`. ###Plugins -Want a yml, xml, database version ? +Want a yml, xml version ? Write your own TranslationRepository! #fast_gettext/translation_repository/xxx.rb module FastGettext module TranslationRepository class Wtf @@ -143,9 +155,11 @@ === - [Problems with ActiveRecord messages?](http://wiki.github.com/grosser/fast_gettext/activerecord) TODO ==== + - some cleanup required, repositories should not have locale + - DB::TranslationKey responds_to? :available_locales should be false when it is not defined, maybe testing bug - use `default_locale=(x)` internally, atm the default is available_locales.first || 'en' - use `default_text_domain=(x)` internally, atm default is nil... Author ======