0

我正在完成我的网站的不同本地化,我在设计电子邮件模板中遇到了一个小问题。设计 - 如何翻译自动生成的链接

在例如确认电子邮件,我已经翻译了这一切,但链接确认帐户中生成使用这个片段汽车:

<%= link_to t('devise.mailer.confirmation_instructions.confirm_link'), confirmation_url(@resource, :confirmation_token => @token) %> 

这个自动生成的总是链接指向我的.COM网页版和我希望它是有条件的取决于域(.com/.es)。当链接是不会产生我可以做到,使用汽车:

if request.host.split('.').last == "com" 

if request.host.split('.').last == "es" 

但在这种情况下,我不知道我能做到这一点。

有什么建议吗?

谢谢。主机参数去你confirmation_url(@resource,:confirmation_token => @token)

+0

您是否以某种方式为用户存储当前的语言设置? – Bartosz

+0

您可以将':host'参数传递给'url'帮助器。 – Bartosz

+0

我在用户表中存储了一列,用于存储用户浏览器的语言。我怎么能通过:主机参数? <%= link_to t('devise.mailer.confirmation_instructions.confirm_link'),confirmation_url(@resource,:confirmation_token => @token,:host =>'www.example.com')%>这种方式? –

回答

1

您可以在添加,并查找正确的主机在转换表:

confirmation_url(@resource, :confirmation_token => @token, host: t('host')) 

在你的YAML文件,你'翻译'正确的主机为用户的语言,就像

en: 
    host: 'www.example.com'