model names and underscores

97 views
Skip to first unread message

Johannes Fahrenkrug

unread,
Nov 7, 2008, 10:35:22 AM11/7/08
to rails-i18n
Hi,

I have a problem: model names with underscores are not picked up from
the locale yml file:

de:
activerecord:
models:
file_item: "Akte"
category: Kategorie
access_group: Zugriffsgruppe
responsible_person: Zustaendige(r)
user: Benutzer
attributes:
file_item:
title: Titel


category become "Kategorie", but file_item doesn't become "Akte". the
attributes, however, work: "title" becomes Titel.
Do you have any suggestions for a workaround/fix?

Thanks!

- Johannes
--
http://springenwerk.com

Sven Fuchs

unread,
Nov 17, 2008, 2:12:57 PM11/17/08
to rails...@googlegroups.com
Hi Johannes,

am I right that your model classes have camelcased names like
FileItem, AccessGroup etc?

Can you provide some more context about what exactly you are doing?
Are you talking about validation messages? Or something else?

This is the line where ActiveRecord validations look up the messages
with various default keys:

http://github.com/rails/rails/tree/master/activerecord/lib/active_record/validations.rb#L92

Erik Dahlstrand

unread,
Nov 18, 2008, 9:40:21 AM11/18/08
to rails-i18n
I have the exact same problem.

Example:

app/models/news_item.rb
class NewsItem < ActiveRecord::Base
end

app/locales/activerecord_sv.yml
sv:
activerecord:
models:
news_item:
one: "Nyhet"
many: "Nyheter"

error_messages_for generates...

"3 fel: news item kunde inte sparas."

should be...

3 fel: Nyhet kunde inte sparas.

The attributes for "underscore models" are translated correctly. The
names for models with no underscore file names are also translated
correctly.

/Erik


On 17 Nov, 20:12, Sven Fuchs <svenfu...@artweb-design.de> wrote:
> Hi Johannes,
>
> am I right that your model classes have camelcased names like  
> FileItem, AccessGroup etc?
>
> Can you provide some more context about what exactly you are doing?  
> Are you talking about validation messages? Or something else?
>
> This is the line where ActiveRecord validations look up the messages  
> with various default keys:
>
> http://github.com/rails/rails/tree/master/activerecord/lib/active_rec...

Johannes Fahrenkrug

unread,
Nov 18, 2008, 10:39:39 AM11/18/08
to rails-i18n
Hi Sven,

sorry for the late reply. Yes, I'm talking about validation messages.
It should be
Konnte diese Akte nicht speichern: 2 Fehler
but instead it is
Konnte diese file item nicht speichern: 2 Fehler
Note that "file item" has no underscore in the message! But in the YML
and in the file name itself - file_item.rb - it does have an
underscore of course.

I looked into this a bit and it seems that activerecord/base.rb
human_name is never called. I edited it to always return "Bla", but
that didn't change anything. Changing human_attribute_name to always
return "Bla", did work, however.

I was under the impression that human_name is called here:
http://github.com/rails/rails/tree/master/activerecord/lib/active_record/validations.rb#L104
But when I change
:model => @base.class.human_name,
to
:model => "Bla",

it dosen't make a difference, either. weird!

- Johannes
Reply all
Reply to author
Forward
0 new messages