Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the way to translate model attributes in rails with mongoid?

I've problem with mongoid and model translations. When I'm trying use mongoDB on my model I haven't idea to translate attributes and model name. It's normally in *.yml files but in this time this doesn't work. Any ideas?

like image 855
Michał Górski Avatar asked Aug 12 '10 07:08

Michał Górski


2 Answers

Variant with "activemodel" does not work for me. But.

This variant worked for me:

 en:
  mongoid:
    errors:
      models:
        user:
          attributes:
            email:
              blank: "You have to give me your e-mail address"
              not_found: "e-mail address not found in list of members"
              #...
    attributes:
      user:
        email: "Email address"
        name: "Your nickname"
        #...

From here

like image 91
Pavel Maksimenko Avatar answered Oct 14 '22 14:10

Pavel Maksimenko


Try this in the yml file (config/locales/pt-BR.yml in my case):

 activemodel:
    attributes:
      [model_name]:
        [attribute1]: "[translation1]"
        [attribute2]: "[translation2]"
        [attribute3]: "[translation3]"

Worked for me, using mongoid 2.0.0.beta.17 and rails 3.0.0

like image 44
Leonardo Cardoso Avatar answered Oct 14 '22 12:10

Leonardo Cardoso