Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting strings from i18n YAML file?

I have some view code:

<span data-something="[<%= t('.asd') %>, <%= t('.dsf') %>]></span>

I use this code to get some dynamic strings translated into the view. My YAML is something like:

en:
  feature:
    asd: "Asdddd"
    dsf: "adasdsadasda"

Is there a way I can use to dynamically get all the "features" from the YAML by locale and put it in the data-attribute?

like image 872
caarlos0 Avatar asked Feb 07 '13 13:02

caarlos0


2 Answers

This is pretty simple to do:

I18n.translate('feature').values.join(', ') 

You'll end up with a string "Asdddd, adasdsadasda".

like image 136
danielricecodes Avatar answered Nov 20 '22 21:11

danielricecodes


I think it's as easy as t('feature') to get the hash, you might want to just have the values so could you try t('feature').keys?

like image 2
Jakob W Avatar answered Nov 20 '22 23:11

Jakob W