Closed hinrik closed 12 years ago
Hi
@hinrik @berk I send emails through background jobs using resque gem. In email's template I am using tr() for localization. Problem is, email does not translate. User will get all the text in English. Even it does not add phrases of email template.
Thanks in advance.
Are you setting current_language in Tr8n::Config based on the user preference. Since you are doing it in the background, you need to manually set it before the email is generated.
If the email is sent out in default language (English), it won’t register phrases - for performance reasons.
On Jun 27, 2014, at 5:54 AM, Afzal Masood notifications@github.com wrote:
Hi
@hinrik @berk I send emails through background jobs using resque gem. In email's template I am using tr() for localization. Problem is, email does not translate. User will get all the text in English. Even it does not add phrases of email template.
Thanks in advance.
— Reply to this email directly or view it on GitHub.
@berk I am very Thankful for your response. Yes, I am setting current_language in Tr8n::Config based on the user preference. If I check Tr8n::Config.current_language.locale in self.perform method of "resque" then it gives me "en-US"
Now I am not sure how to change language, If I set language like following in resque's self.perform method
Tr8n::Config.current_language.locale = "de" or like this Thread.current[:tr8n_current_language] = Tr8n::Language.for("de")
then resque does not deliver email and show following error at resque admin view:
undefined method translation_key_for_key' for nil:NilClass at tr8n-973fb5277bfe/app/models/tr8n/translation_key.rb:79:in
find_or_create'
Second, If I set Tr8n::Config.current_language.locale = "de" in mailer method then it sends email again in English and do not add phrases of emails content.
Third, If I use tr('Hello', "Greetings", {:locale => "de"}) then it also does nothing.
E.g. when sending emails.