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

- old
+ new

@@ -1,8 +1,8 @@ FastGettext =========== -GetText but 8 x faster, 72 x less memory, simple, clean namespace (7 vs 34) and threadsave! +GetText but 3.5 x faster, 20 x less memory, simple, clean namespace (7 vs 34) and threadsave! [Example Rails application](https://github.com/grosser/gettext_i18n_rails_example) Setup ===== @@ -37,27 +37,28 @@ Performance =========== 50_000 translations speed / memory small translation file <-> large translation file Baseline: (doing nothing in a loop) - 0.420000s / 0K <-> + 0.240000s / 1196K <-> Ideal: (primitive Hash lookup) - 1.170000s / 112K <-> 1.170000s / 112K + 0.790000s / 1200K <-> 0.760000s / 1200K FastGettext: - 1.960000s / 136K <-> 1.950000s / 268K + 1.360000s / 1200K <-> 1.340000s / 1200K - GetText 2.0: - 15.490000s / 8872K <-> 15.510000s / 9336K + GetText 2.0.1: + 4.810000s / 6.176K <-> 4.770000s / 6.176K ActiveSupport I18n::Backend::Simple : - 32.470000s / 9484K <-> + 21.800000s / 11296K <-> + 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...). @@ -93,11 +94,11 @@ 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 code/specs), or by using the Gettext +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). ###default_text_domain If you only use one text domain, setting `FastGettext.default_text_domain = 'app'` is sufficient and no more `text_domain=` is needed @@ -105,36 +106,36 @@ ###default_locale If the simple rule of "first `availble_locale` or 'en'" is not suficcient for you, simply set `FastGettext.default_locale = 'de'`. ###Chains You can use any number of repositories to find a translation. Simply add them to a chain and when -the first cannot translate a given key, the next is asked and so forth. +the first cannot translate a given msgid, the next is asked and so forth. repos = [ - FastGettext::TranslationRepository.build('old', :path=>'....'), - FastGettext::TranslationRepository.build('new', :path=>'....') + FastGettext::TranslationRepository.build('new', :path=>'....'), + FastGettext::TranslationRepository.build('old', :path=>'....') ] FastGettext.add_text_domain 'combined', :type=>:chain, :chain=>repos -#Logger -When you want to know which keys could not be translated, or where used, add a Logger to a Chain: +###Logger +When you want to know which keys could not be translated or were used, add a Logger to a Chain: repos = [ FastGettext::TranslationRepository.build('app', :path=>'....') FastGettext::TranslationRepository.build('logger', :type=>:logger, :callback=>lamda{|msgid_or_array_of_ids| ... }), } FastGettext.add_text_domain 'combined', :type=>:chain, :chain=>repos 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 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 ? Write your own TranslationRepository! #fast_gettext/translation_repository/xxx.rb module FastGettext module TranslationRepository class Wtf define initialize(name,options), [key], plural(*msgids) and - either inherit from Base or define available_locales and pluralisation rule + either inherit from TranslationRepository::Base or define available_locales and pluralisation_rule end end end FAQ