我添加了devise_invitable gem和自定义邮件程序。它正常工作,正常设计电子邮件(例如confirm_instructions)正在正确读取i18n文件,但邀请函不是。
这是devise.en.yml:
en:
devise:
mailer:
confirmation_instructions:
subject: "Hi %{first_name}, please confirm your email to activate your account"
invitation_instructions:
subject: "%{first_name} has invited you to join their team!"
hello: "Oi"
someone_invited_you: "Pig"
自定义邮件程序类:
class CustomDeviseMailer < Devise::Mailer
def confirmation_instructions(record, token, opts={})
custom_options(record, opts, :confirmation_instructions)
super
end
def invitation_instructions(record, token, opts={})
custom_options(record, opts, :invitation_instructions)
super
end
private
def custom_options(record, opts, key)
opts[:subject] = I18n.t('subject', scope: [:devise, :mailer, key], first_name: record.first_name)
end
end
如果我将invitation_instructions方法更改为:
def invitation_instructions(record, token, opts={})
custom_options(record, opts, :invitation_instructions)
opts[:subject] = "TEST"
super
end
然后邀请电子邮件主题正确更改为“测试”。
那为什么不读i18n文件呢?
注意
我还生成了默认的邀请视图,也没有读取i18n文件。例如,默认视图的第一行是:
\应用\视图\色器件\邮包\ invitation_instructions.html.erb
<p>
<%= t("devise.mailer.invitation_instructions.hello", email: @resource.email) %>
</p>
哪个应该呈现&#39; Oi&#39;来自i18n文件,但它呈现默认的&#39; Hello&#39;代替。
答案 0 :(得分:0)
事实证明,devise_invitable gem不会读取devise.en.yml,因为它会创建其OWN语言环境文件:
devise_invitable.en.yml
所以我需要进行文本自定义。