设计一种资源



我正在尝试使用区域设置将设计默认语言(英语)翻译为葡萄牙语。我找到了一个很好的资源,它在大多数情况下都能工作,但每当我在locale中有一个指向资源变量的指针时它就会给我英文名。例如,我有一个名为User的模型,因此当更新此用户时出现问题时,我希望显示包含"User"正确翻译的flash消息,在本例中为"Usuário"。

模型名翻译应该放在config/locales/pt.yml

pt:
  activerecord:
    models:
      user: Usuário

设计不使用ActiveRecord翻译,可能不会与任何ORM耦合。

我刚刚用ActiveRecord键重写了添加翻译的设计视图:

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"

要翻译其他消息(不是字段标签),您应该尝试https://github.com/mcasimir/devise-i18n-views

最新更新