【发布时间】:2014-07-04 08:55:40
【问题描述】:
假设我在一个 I18n 文件中有两个 yaml 键:
level1:
level2:
foo: 'Something'
bar: 'Something else'
我会像这样引用这些键:t('level1.level2.foo') 和 t('level1.level2.bar')。如果我有一个变量var,它的类型返回'foo' 或'bar',我可以这样做:t('level1.level2.#{var.type}')。现在更棘手的部分 - 如果我已经在字符串插值中使用了键怎么办:
"The type of the #{var.to_s} variable is #{t('level1.level2.#{var.type}')}"
【问题讨论】:
标签: ruby-on-rails internationalization yaml interpolation