简体   繁体   中英

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

您可以传递语言环境选项:

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

Read the documentation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM