2

I am using devise_invitable gem in rails and I have configured a number of locales in my rails app. What I would like to do is to invite a user with a locale I would specify myself. I t could look something like this:

User.invite!(:email => "test@example.com", :locale => 'fr')

This would send an email with the 'fr' as locale , even when I18n.locale would be en.

Is this possible, even with a complete different syntax than the one I am using above ?

rpechayr
  • 1,282
  • 12
  • 27

1 Answers1

0

Digging, I found that devise_invitable uses the devise mailer, see source. I'm not 100% sure how I18n.t exactly works, but I suppose you know that. So use alias_method_chain to monkey-patch the translate method. To pass the other language, you can choose one:

  1. modify the whole call stack to pass down the variable
  2. use a pseudo-global variable via Thread.current[].

I propose to use 2., make your choice. Then use that variable to return the correct translation.

Reactormonk
  • 21,472
  • 14
  • 74
  • 123