Search code examples
ruby-on-rails-3activerecordinternationalizationobservers

Using translation in observer


I started cleaning up my models and controllers by outsourcing the sending of notification mails into an observer.

There is one problem I noticed by moving this from controller to observer: If I call 'translate' or the shorthand 't' I get the answer "Method not defined"

Ok, I really like the rails implementation for internationalisation. But how can it be used in models and observers?


Solution

  • You can call the method via the I18n object:

    I18n.t :whatever