是否存在布尔值的现有I18N翻译? [英] Is there an existing I18N translation for booleans?
本文介绍了是否存在布尔值的现有I18N翻译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要根据表达式是对还是错,以各种语言显示是"或否".目前,我正在这样做:
I need to display "Yes" or "No" in various languages based on whether a expression is true or false. Currently I am doing it like this:
fr:
"yes": Oui
"no": Non
辅助方法:
def t_boolean(expression)
(expression) ? t("yes") : t("no")
end
erb:
Valid: <%= t_boolean(something.is_valid?) %>
有更好的方法吗?
Rails已有这样的对/错翻译吗?
Does Rails already have translations for true/false like this?
推荐答案
After reading this, I got inspired and figured out this solution:
fr:
"true": Oui
"false": Non
erb:
Valid: <%= t something.is_valid?.to_s %>
更新
对于英语,如果要使用yes
和no
作为值,请确保用引号引起来:
For english, if you want to use yes
and no
as values, be sure to quote them:
en:
"true": "yes"
"false": "no"
这篇关于是否存在布尔值的现有I18N翻译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文