I know that the answer has already been accepted, but this question gave me some food for thought, and I thought that I would share a different structure for the Rails i18n yml files for your consideration / criticism.
Given that I would like
- keep the default structure of the application so that I can use shorthand "lazy" queries, for example
t('.some_translation') in my views, - avoid as many line repeats as possible, in particular with words that are not the same but also have the same contexts / meanings,
- you only need to change the key once so that it is reflected everywhere that it referred to,
for the config / locales / en.yml file , which looks something like this:
activerecord: attributes: user: email: Email name: Name password: Password password_confirmation: Confirmation models: user: User users: fields: email: Email name: Name password: Password confirmation: Confirmation sessions: new: email: Email password: Password
I see that there is significant repetition, and that the context of words such as "Email" and "Password" is unambiguous and has the same meaning in their respective representations. It would be a little annoying that I need to go and change them all if I decide to change "Email" to "e-mail", so I would like to reorganize the lines for a link to some kind of dictionary. So, how about adding a hash dictionary to the top of the file with some anchored & :
dictionary: email: &email Email name: &name Name password: &password Password confirmation: &confirmation Confirmation activerecord: attributes: user: email: *email name: *name password: *password password_confirmation: *confirmation models: user: User users: fields: email: *email name: *name password: *password confirmation: *confirmation sessions: new: email: *email password: *password
Whenever you get more than one copy of exactly the same word / phrase in your submissions, you can reorganize it in the dictionary. If translating the dictionary in the base language does not make sense for the target language, simply change the reference value in the target language to a static string or add it as an additional entry to the dictionary of the target language. I am sure that each dictionary of the language can be reorganized into a different file if they become too large and bulky.
This way of structuring the i18n yaml files seems to work well with some local test applications in which I tried it. I hope the great Localeapp will provide support for this type of anchor / link in the future. But, in any case, all these vocabulary conversations cannot be an original idea, are there any other problems with binding binding in YAML, or maybe just with the general concept of a “dictionary” in general? Or is it simply better to just completely remove the default backend and replace it with Redis or something else?
Paul Fioravanti Jun 18 '12 at 20:00 2012-06-18 20:00
source share