Internationalization of MongoMapper

112 views
Skip to first unread message

Kratos

unread,
Feb 16, 2010, 8:50:59 AM2/16/10
to MongoMapper
Is it possible to localize error messages from MongoMapper? I search
many hours but nothing found.

thanks!

John Nunemaker

unread,
Feb 16, 2010, 10:51:50 AM2/16/10
to mongo...@googlegroups.com
Not right now. Validatable would need to be updated and I have never used/needed internationalization so I won't be doing it. Someone else would have to lead the effort. 


--
You received this message because you are subscribed to the Google
Groups "MongoMapper" group.
For more options, visit this group at
http://groups.google.com/group/mongomapper?hl=en?hl=en

Jamie van Dyke

unread,
Feb 16, 2010, 11:47:19 AM2/16/10
to MongoMapper
It isn't hard if you just want validation errors to be
internationalized. Examples re-using ActiveRecord's default messages:

validates_presence_of :name,
:message => lambda
{ I18n.translate("activerecord.errors.messages.blank") }
validates_uniqueness_of :slug,
:message => lambda
{ I18n.translate("activerecord.errors.messages.taken") },
:case_sensitive => false

Cheers
-- Jamie van Dyke

Kratos

unread,
Feb 16, 2010, 3:06:37 PM2/16/10
to MongoMapper
Thanks Jamie, works like a charm!

Emilien Taque

unread,
Mar 2, 2010, 3:47:03 AM3/2/10
to MongoMapper
Hello,
I'm trying to translate my error messages in french.
The previous trick allows me to get the sentence translated, but
neither the attribute name nor the model are translated in this
sentence.
The mongomapper_i18n gem works fine : human_name and
human_attribute_name methods return the translated values.

The problem is that Validatable seems to create it's own human_name
without calling the model method :

full_messages << humanize(attribute.to_s) + " " + msg

def humanize(lower_case_and_underscored_word) #:nodoc:
lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/,
" ").capitalize
end

Do you know how to deal with in an elegant way ?

Thank you,
Emilien

Reply all
Reply to author
Forward
0 new messages