我想为
创建一个条件t(foo.bar)
如果foo.bar不存在则返回false,如果yml文件中存在则返回true,如下所示。
foo:
bar: here
答案 0 :(得分:0)
You can try using I18n.t!
and rescue the I18n::MissingTranslationData
exception it raises if the key is missing:
def translation_exists?(key)
begin
I18n.t!(key)
true # or just return the result of t! as it's truthy.
rescue => I18n::MissingTranslationData
false
end
end