I'm trying to use locale to translate devise default language (english) to portuguese. I've found a pretty good resource for that, it's working for the most part, but whenever I have a pointer to the resource variable inside the locale it gives me the name in English. For example, I have a model called User, so when something goes wrong while updating this user I would like to show a flash message containing the right translation of "User", in this case "Usuário".
Asked
Active
Viewed 1,394 times
2 Answers
3
model names translations should be put to config/locales/pt.yml
pt:
activerecord:
models:
user: Usuário

binarycode
- 1,788
- 15
- 15
-
Is your locale set to Portuguese? What exact messages are left untranslated? – binarycode Sep 01 '11 at 05:45
-
Yes, it's set correctly. Well, only the error message on the resource. The entry on the locale config is as follow: under errors/messages/not_saved: one: "Não foi possível gravar o %{resource}: 1 erro" If I change the "resource" for "model" it says it's missing an interpolation argument. – Raphael Melo Sep 01 '11 at 11:51
-
It is not working cause Devise uses some kind of 'resource' rather than ActiveRecord object. Look at Devise::RegistrationsController.new – Kangur Feb 15 '13 at 15:41
0
Devise doesn't use ActiveRecord translations, probably not to couple with any ORM.
I've just ended up overriding devise view adding translation with ActiveRecord keys:
h2 =t('.sign_up')
= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => {:class => 'form-vertical' }) do |f|
= f.error_notification
= display_base_errors resource
= f.input :name, label: t('activerecord.attributes.user.name'), :autofocus => true
= f.input :email, label: t('activerecord.attributes.user.email'), :required => true
= f.input :password, label: t('activerecord.attributes.user.password'),:required => true
= f.input :password_confirmation, label: t('activerecord.attributes.user.password_confirmation'), :required => true
= f.button :submit, t('.sign_up'), :class => 'btn-primary'
= render "devise/shared/links"
For translating other messages (not field labels) you should try https://github.com/mcasimir/devise-i18n-views

Kangur
- 7,823
- 3
- 30
- 32