I have the following translation file:
ru:
common:
age:
- год
- года
- лет
and I want to access list items in tranlsation. I tried something like:
t('common.age[2]')
But it doesn't work. How to do it properly?
I have the following translation file:
ru:
common:
age:
- год
- года
- лет
and I want to access list items in tranlsation. I tried something like:
t('common.age[2]')
But it doesn't work. How to do it properly?
You can store an array structure in YAML but you can't iterate over one in YAML-land. YAML is a data serialisation language, and is not meant to contain executable statements (
Array#[]
is a Ruby method call), only data structures. Executable statements are the responsibility of the programming language you're working with, in your case Ruby.So, in your case, you need to use
t('common.age')
to first pull out the array from YAML, then iterate over it in Ruby-land: