简体   繁体   中英

How to translate conditional statement in i18n

I'm having a hard time providing I18n support for the statement below. How do I provide i18n for 'Update User' and 'Create New User'?

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

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.

我知道 Hesham 已经回答了,但您也可以通过以下方式进行

@user.new_record? ? t('.update_user') : t('.create_new_user')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM