ruby - Rails I18n nested translation keys -
is there way nest translation lookups? this:
en: uh_oh: 'uh oh!' error1: :'uh_oh' + ' there big error!' error2: :'uh_oh' + ' there big error!'
i18n.t('error1') #=> 'uh oh! there big error!' i18n.t('error2') #=> 'uh oh! there big error!'
i've tried bunch of variations of this, , tried using ruby translation file instead of yaml. note does work:
en: uh_oh: 'uh oh!' error1: :'uh_oh'
i18n.t('error1') #=> 'uh oh!'
but if add additional text error1
, uh_oh
doesn't translated.
basically want avoid having pass in common terms, this:
en: uh_oh: 'uh oh!' error1: '%{uh_oh} there big error!'
i18n.t('error1', {uh_oh: i18n.t('uh_oh')})
for common terms uh_oh
, interpolation same every call error1
(and other key uses uh_oh
), doesn't make sense have pass in string interpolated. it'd easier following instead , have error1
translation take care of common key translation:
i18n.t('error1')
i'm not going answer question (i don't think it's possible i18n gem wrong). going shouldn't take approach , give link [1] background. developers it's natural see patterns , extract common code keep things dry. step far when dealing multiple languages prevents proper translations. not languages follow same sentence structure english , you're substituting in may have change agree rest of sentence.
on site work on have problem french. have sentences include location name , straightforward in english. "%{location_name} property" works whatever location name is. in french however, need different structures depending on whether location town, province, region, , whether name starts vowel or not.
Comments
Post a Comment