ruby-on-railsinternationalizationrails-i18nclockwork

I18n together with clockwork


When a model method "model_method" is called from clockwork, I18n.locale always equals to my default locale.

How do I pass the current locale to the model method?

Part of clockwork.rb:

every(10.minutes, 'test') do
  Book.delay(:queue => 'some_queue').model_method
end

Part of book.rb:

def self.model_method
  ...
  message = I18n.t('some_text')
  # always equals to ":en"
end

Solution

  • You can pass a locale option:

      message = I18n.t('some_text', locale: 'en')
    

    Read the documentation.