FastGettext/Rails integration, simple, threadsafe and fast!
Switch branches/tags
Nothing to show
Pull request Compare This branch is 1 commit ahead, 485 commits behind grosser:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Simple FastGettext / Rails integration.

The idea is simple: use Rails I18n::Simple for all default translations,
and do our own translations with FastGettext!

Rails does: I18n.t('weir.rails.syntax.i.hate')
We do: _('Just translate my damn text!')

See it working in the example application.


###Installation This plugin: ./script/plugin install git:// FastGettext: sudo gem install grosser-fast_gettext -s GetText 2.0 & GetText::ActiveRecord 0.1: rake gettext:install

Locales & initialisation

Copy default locales you want from e.g.
into 'config/locales'

#environment.rb do |config|
  config.gem "grosser-fast_gettext", :lib => 'fast_gettext', :version => '0.2.6', :source=>""
FastGettext.add_text_domain 'app', :path => File.join(RAILS_ROOT, 'locale')

class ApplicationController < ...
  before_filter :set_gettext_locale
  def set_gettext_locale
    FastGettext.text_domain = 'app'
    FastGettext.available_locales = ['en','de'] #all you want to allow


  • use some _('translations')
  • run rake gettext:find, to let GetText find all translations used
  • if this is your first translation: cp locale/app.pot locale/de/app.po for every locale you want to use
  • translate messages in 'locale/de/app.po' (leave msgstr blank and msgstr == msgid)
    new translations will be marked "fuzzy", search for this and remove it, so that they will be used. Obsolete translations are marked with ~#, they usually can be removed since they are no longer needed
  • run rake gettext:pack to write GetText format translation files


Car|Model means Model in namespace Car.
You do not have to translate this into english "Model", if you use the namespace-aware translation s_('Car|Model') == 'Model' #when no translation was found


GetText supports pluralization n_('Apple','Apples',3) == 'Apples'

Unfound translations

Sometimes GetText cannot find a translation like _("x"+"u"),
for this cases either add N_('xu') somewhere else in the code,
where it can be seen by GetText, or even in a totally seperate file like
unfound_translations.rb, or use the gettext_test_log rails plugin
to find all translations that where used while testing.

###Improving Rails translations You certanly want to add at least: #de.yml active_record: models: car: 'Auto' ... So that Rails error messages use the translated version of your model. more help


GetText -> Masao Mutoh, from whom i learned how the internals work :) FastGettext -> Me

Michael Grosser
Hereby placed under public domain, do what you want, just do not hold me accountable...