Reputation: 6206
I'm working with a legacy database schema which uses camelCase for its attributes, which Rails doesn't translate too well into human readable form. For one model I can define eg.
en:
active_record:
attributes:
user:
createDate: "Create date"
But that works only for the User model. Is there a way to define "global attribute translations"? Something like
en:
activerecord:
attributes:
global:
createDate: "Create date"
Thanks you.
Upvotes: 2
Views: 806
Reputation: 4136
Rails will lookup translations for attributes in the following places (if your attribute name is not namespaced):
(take a look at the ruby docs for human_attribute_name)
so to achieve what you're looking for above you should use the following:
en:
attributes:
createDate: "Create date"
you can still override these 'default' attribute names by adding translations like your first example e.g.
en:
active_record:
attributes:
user:
createDate: "User creation date"
will result in:
User.human_attribute_name(:createDate) => "User creation date"
Topic.human_attribute_name(:createDate) => "Create date"
SomeOtherModelClass.human_attribute_name(:createDate) => "Create date"
Upvotes: 7