Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I18N key for rails models grouped in a module

I have several models grouped in a module like this:

  #/app/models/blobs/small_text.rb
  class Blobs::SmallText < ActiveRecord::Base

        #.. class implementation

  end

I would like to set the human class name to "Texte Court" in French :

  I18n.locale = "fr"
  Blobs::SmallText.model_name.human # should return "Texte Court" 

I'm having trouble with the module part of the class definition and how it should be included in locale files. I've tried several combinations in my locale files but dit not work. Here are some combinations I've tried:


  # /config/locales/models/blobs.fr.yml

  # first attempt (does not work)
  fr:
    activerecord:
      models:
         blobs_small_text: "Texte Court"

  # /config/locales/models/blobs.fr.yml   
  # second attempt(does not work) 
  fr:
    activerecord:
      models:
         blobs:
           small_text: "Texte Court"

Any ideas? Thanks D.

like image 860
Dorian Avatar asked May 02 '12 13:05

Dorian


1 Answers

Ok. I thing I found the answer. When you don't know the class key just run in a rails console the following instruction:

 Blobs::SmallText.model_name.i18n_key  # this returns :"blobs/small_text"

Now I can update my locale files accordingly:

# /config/locales/models/blobs.fr.yml
# last attempt (it works)
fr:
  activerecord:
    models:
       blobs/small_text: "Texte Court"

So now it works. However, is it just me or this naming convention does not respect the general naming conventions in Ruby on Rails?

like image 153
Dorian Avatar answered Sep 30 '22 02:09

Dorian