[英]string interpolation in devise flash messages?
I'm new to RoR and I would like to personalise the Devise flash messages to use the name of the current user. 我是RoR的新手,我想个性化Devise flash消息以使用当前用户的名字。
I've seen that the original file includes the following line: 我已经看到原始文件包含以下行:
devise.en.yml devise.en.yml
failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
So I've applied the same rule to: 所以我已经应用了相同的规则:
sessions:
signed_in: "Welcome back!."
signed_out: "See you soon!."
- -
sessions:
signed_in: "Welcome back! \"#{current_user.first_name}\"."
signed_out: "See you soon! \"#{current_user.first_name}\"."
but the code is not executing, and prints the whole sentence as string. 但代码没有执行,并将整个句子打印为字符串。
Any help would be appreciated! 任何帮助,将不胜感激! :) :)
It should be 它应该是
sessions:
signed_in: "Welcome back! %{name}."
signed_out: "See you soon! %{name}."
And you must call it like: 你必须把它称为:
t('sessions.signed_in', name: current_user.first_name)
t('sessions.signed_out', name: current_user.first_name)
You can't use ruby interpolation in yml
file but you can pass variable to the translation
and use yml
interpolation syntax %{}
您不能在yml
文件中使用ruby插值,但可以将变量传递给translation
并使用yml
插值语法%{}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.