[英]How to translate conditional statement in i18n
I'm having a hard time providing I18n support for the statement below.我很难为下面的语句提供 I18n 支持。 How do I provide i18n for 'Update User' and 'Create New User'?
如何为“更新用户”和“创建新用户”提供 i18n?
h1 = @user.persisted? ? 'Update User' : 'Create New User'
Normally you should just add t('.what_you_need_to_translate')
, so in your case it will be通常你应该只添加
t('.what_you_need_to_translate')
,所以在你的情况下它将是
h1 = @user.persisted? ? t('.update_user') : t('.create_new_user')
Of course that's taking into consideration that you have the 'rails-i18n'
gem and that the mentioned translations are existing in the correct files.当然,这是考虑到您拥有
'rails-i18n'
gem 并且提到的翻译存在于正确的文件中。
我知道 Hesham 已经回答了,但您也可以通过以下方式进行
@user.new_record? ? t('.update_user') : t('.create_new_user')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.