Question

Using shorter i18n keys (e.g. t '.submit_button') in Rails views makes them easier to type, but is it actually good? When later you decide to refactor your views and partials you have to remember to update the respective localization entries. Wouldn't it be more robust to name them by their business meaning and always specify the full key-name?

Was it helpful?

Solution

Well, I'm using a mixture. ;-)

For things like "yes", "no", "submit", "cancel" I tend to use a namespace called "defaults" so I always use it like t 'defaults.cancel'. That could also address the "submit_button" thing you mentioned above. For my specific views I decided to use the lazy lookup feature.

If you want I18n keys for specific views you have to decide what fits best for you:

  • If you don't mind searching your yaml file for the I18n keys and change them if you change the view do so. The advantage is that you save some characters for each I18n.t call of it in your view.

  • But if you change your view names very often (not sure why you should have to do so :) ) then you might be better of using the way you described.

As I already said I prefer the first option since it's more convenient for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top