How to i18n a namespaced model

455 views
Skip to first unread message

Gustavo de Sá Carvalho Honorato

unread,
Sep 1, 2011, 3:31:46 PM9/1/11
to plataformate...@googlegroups.com
Hi,

I can't figure out how to i18n namespaced models. Here is an example model:

#user.rb
class Admin::User < ActiveRecord::Base

end

I've tried this:
#pt-BR.yml

activerecord:
  models:
    admin:
      user: "Usuário"

and this:

#pt-BR.yml
activerecord:
  models:
    admin/user: "Usuário"

None of two options worked.

Please, help me.

Thanks in advance,
Gustavo

Carlos Antonio

unread,
Sep 1, 2011, 3:50:05 PM9/1/11
to plataformate...@googlegroups.com
Hey Gustavo,

Rails converts the namespace to a "shallow" object name attribute to be used internally in the form, which is the one SimpleForm bases its translation. The translation key should be "admin_post", I believe that should work properly.

-- 
At.
Carlos Antonio

Gustavo de Sá Carvalho Honorato

unread,
Sep 1, 2011, 5:17:13 PM9/1/11
to plataformate...@googlegroups.com
Hi Carlos,

thanks for your fast answer. I've tried with this "shallow" object name too, but I forgot to mention. I tried again after your suggestion and it didin't work again. I tried this in both simple_form.pt-BR and pt-BR.yml. I really don't now what else I can do. 

I'm using Rails 3.1 FINAL and ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]. Do you think that could be an issue with these versions?

Thanks again,
Gustavo

Carlos Antonio

unread,
Sep 1, 2011, 5:29:20 PM9/1/11
to plataformate...@googlegroups.com
Weird.. I created an example scaffold here just to test and it worked fine =(. But I tested it within SimpleForm labels i18n, not AR models.

I've also created another app, with a new scaffold and change the i18n file like this:

    en:
      hello: "Hello world"

      activerecord:
        models:
          admin/user: "Usuário"

And the console gives me the right values:

    >> Admin::User.model_name.i18n_key
    => :"admin/user"
    >> Admin::User.model_name.human
    => "Usuário"

I'm not sure the problem would be your configuration. I used Rails 3.1 as well in the examples, but I'm using REE (which I think should not be the problem).

Could you try creating a bare app to see if that works? Maybe also try using SimpleForm labels scope, as I've mentioned, just to check? If that still does not work for you, I'll have to ask you this example app showing the issue so we can check. Thanks.

-- 
At.
Carlos Antonio

Gustavo de Sá Carvalho Honorato

unread,
Sep 9, 2011, 2:27:56 PM9/9/11
to plataformate...@googlegroups.com
Hi Carlos,

sorry to take too long to answer. I got sick last couple days and I was unable to test your suggestions. I fixed the problem by rewriting all my translation file. I have no idea what was causing that problem, maybe an mistyped  character. I really don't now, but I'm happy now :)

Thanks again,
Gustavo

Carlos Antonio

unread,
Sep 9, 2011, 3:50:44 PM9/9/11
to plataformate...@googlegroups.com
Hey Gustavo,

don't worry, we all get sick from time to time, I'm a bit now, btw. The good news are that you got better and I'm finally getting better as well \o/.

I'm just happy to know that everything is working fine and it wasn't a SimpleForm bug :D.
Regards.

-- 
At.
Carlos Antonio

Reply all
Reply to author
Forward
0 new messages