views:

17

answers:

1

Hi ,

I am new to ROR. I am trying add translations to my application. I have added translations for the controllers.

  1. Where to add translations for models as i am not having any /config/locales -> models folder ->en.yml file .

  2. In the model i am having lines like validates_presence_of :name, :message => "Name cannot be blank!"

If i want to add translations for the message "Name cannot be blank", shall i put directly as like

validates_presence_of :name, :message => I18n.t(str_name_notblank)

Please give suggestions

+2  A: 

To add translations to your models you just need to put them under activerecord->models and activerecord->attributes. Here's an example in polish:

pl:      
  activerecord:
    models:
      patient: "Pacjent"
    attributes:
      patient:
        first_name: "Imię"
        last_name: "Nazwisko"
        address: "Ulica"
        postal_code: "Kod"
        city: "Miejscowość"

Note that the attributes element is not under the patient element, but actually includes it again. I found this after some debugging and it actually worked for me. The Rails I18n guide suggested a different structure, but it didn't work.

The best way to translate standard Rails messages (like the ones for validation) is to download the correct translation file from Sven Fuchs' Rails Locale Data Repository (rails-18n) and put it into your config/locales folder (you can change the name). Then you'd remove your :message string and just use the standard messages, but translated to your liking.

Matt