设计 i18n 资源

发布于 2024-12-02 08:27:00 字数 174 浏览 0 评论 0原文

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

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".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

八巷 2024-12-09 08:27:00

模型名称翻译应放入 config/locales/pt.yml 中

pt:
  activerecord:
    models:
      user: Usuário

model names translations should be put to config/locales/pt.yml

pt:
  activerecord:
    models:
      user: Usuário
帅气尐潴 2024-12-09 08:27:00

Devise 不使用 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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文