我有以下 locale/*.yml
文件:
en:
hello:
world: World
time:
am: "AM"
pm: "PM"
ja:
hello:
world:
time:
am: "午前"
pm: "午後"
当我尝试调用缺少的语言环境时,后备工作正常:
I18n.locale = :ja
I18n.t('hello.world') => 'World'
但是当我调用父键时,它在某些值上返回“nil”(hello
):
I18n.locale = :ja
I18n.t('hello') => { world: nil, time: { am: "午前", pm: "午後" } }
如何获得带有后备的翻译:{ world: 'World', time: { am: "午前", pm: "午后"} }
最佳答案
您是否尝试使用 :default => ''
选项调用翻译方法?
关于ruby-on-rails - Rails I18n 哈希回退,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39076356/