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.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With