Blog

rails and mongoid i18n model attributes

rails and mongoid i18n model attributes

Today we had a little problem in translate model attributes in one of my recent projects. We use mongodb with the mongoid gem as orm in this project. We create the project with multilingualism and we use the normal i18n gem for that.

Now here is a little tip for fixing model attributes translations in the .yml-Files:

Instead of this:

  en:
    activerecord:
      models:
        user: "Showmaster"
      attributes:
        user:
          email: "E-Mail"

Just write this into your .yml-File:

  en:
    mongoid:
      models:
        user: "Showmaster"
      attributes:
        user:
          email: "E-Mail"

Now you have the normal access to the i18n gem helpers and so on.

This is just a little hint, maybe it will save you some time somedays.

14.03.2012
Matthias Frick
Ruby on Rails
6 Kommentare

Über den Autor

Matthias Frick
Matthias Frick, MSc.

Er ist ein langjähriger Ruby-on-Rails Entwickler und leitet das Unternehmen Frick-Web.

6 Kommentare zu "rails and mongoid i18n model attributes"

  1. fernando mayoral
    fernando mayoral 29.11.2013
    saved me, thanks!
  2. Martina
    Martina 24.10.2014
    such a simple code snippet that saves a lot of time! thanks!
  3. Karsten Meier
    Karsten Meier 09.12.2014
    Thanks, I just got the problem that model translation were not found.
  4. Matthias Frick
    Matthias Frick 09.12.2014
    Hi Karsten! Did you restart your rails application? I am sorry, but maybe something changed in the meantime..this post is quite old..
  5. Karsten Meier
    Karsten Meier 10.12.2014
    Thanks you for asking, I wanted to say: I had a problem and I found the solution here. Everything works after I changed "activerecord" to "mongoid".
  6. Matthias Frick
    Matthias Frick 10.12.2014
    @Karsten: okay I got it now :-). Thought you still have problems.. but I am glad that it works now. Thank's for your feedback.

Kommentar verfassen