【问题标题】:Devise translation in rails在 Rails 中设计翻译
【发布时间】:2013-08-20 11:48:06
【问题描述】:

我已经在设计中注册了,如下所示:

<%= semantic_form_for resource, :as => resource_name, :url => registration_path(resource_name) do |f| %>
<li id='errors'><%= devise_error_messages! %></li>
<span><%= f.label :email ,'Adres email' %></span>
                    <li><%= f.email_field :email %></li>

                    <span><%= f.label :password ,'Hasło' %></span>
                    <li><%= f.password_field :password %></li>

我尝试用 I18n 翻译设计,但没有结果。当我输入错误的密码时,我看到:

Password należy uzupełnić

它的后半部分已翻译,但“密码”一词未翻译。我尝试了很多事情,例如:

 activerecord:
   attributes:
     user:
       password: SHIT

但它不起作用。也试试把它放进去:

errors: &errors
    format: ! '%{attribute} %{message}'

    messages:

但它仍然不起作用。也可以尝试

formtastic:
   user:
       password:

但没有任何效果。我可以在哪里翻译诸如密码、电子邮件、密码确认和表单中的其他值之类的词。

这是一个答案:

activerecord:
  attributes:
    user:
      password: Hasło
      email: Adres email
      password_confirmation: Hasło
    profile:
      age: Wiek

 <<: *errors

【问题讨论】:

  • 不要理解 - 我如何在标签视图中设置 devise_errors
  • 抱歉误会了。忽略它。
  • 你使用的是devise i18n文件吗?
  • AFAIK 如果你在form_for 中有resource,那么你应该在语言环境中为resource 添加属性,现在你在表单中有resource,在语言环境中有user。跨度>
  • 好的,我得到了答案。用户和个人资料的 Activerecord 属性

标签: ruby-on-rails rails-i18n


【解决方案1】:

从设计中简单地检查默认的 en.yml 翻译文件以更改默认值:

https://github.com/plataformatec/devise/blob/master/config/locales/en.yml

复制该文件并创建您自己的翻译……例如 devise.de.yml、devise.es.yml 等等……应该可以解决您的问题。

如果你想翻译你的模型属性,它不依赖于设计。那是正常的 Rails 东西.. 看看这个链接:http://guides.rubyonrails.org/i18n.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多