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".
model names translations should be put to config/locales/pt.yml
pt:
activerecord:
models:
user: Usuário
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
精彩评论