views:

27

answers:

1

Hi, the website I'm developing will be in spanish. Therefore, I'll need the error messages in that language.

I created a file under Configuration directory called 'en.yml' in order to accomplish this. And I added the following code in it:

es:
  activerecord:
    errors:
        models:
          announcement:
            attributes:
             title:
              blank: "El título no puede estar vacío."

"El título no puede estar vacío" means "The title cannot be blank".

When I go and run this code I see a message like the following:

"Title El título no puede estar vacío."

Where "Title" is the field's name. But I don't want it to be displayed. I just want to display the error message I created.

+1  A: 

You have to specify the translation after the attribute

es:
  activerecord:
    models:
      announcement: "Anuncio"
    attributes:
      announcement:
        title: "Título"   # <= here
    errors:
      models:
        announcement:
          attributes:
            title:
              blank: "no puede estar vacío."

See 5.1 Translations for ActiveRecord Models for more information

macek
When I write "Título" as you did above, I see a mark in the NetBeans saying that it expected a <block end> and underlines the last line in red. How can I fix this?
Brian Roisentul
Did I have a syntax error somewhere?
macek
Oh I see the code has been edited now. I saw blank: syntax right after "Titulo", and it threw an exception. It works now. Thanks!
Brian Roisentul
No problem! Check out that guide for all other awesome I18n tips :)
macek