【问题标题】:using i18n with rails 3 problem将 i18n 与 rails 3 问题一起使用
【发布时间】:2010-06-02 13:04:51
【问题描述】:

我有一些用于用户注册的表格,并希望通过 locales yml 文件对其进行本地化。尤其是来自验证的错误。

例如,语言环境文件:

tr:
  activerecord:
    errors:
      models:
        user: 
          attributes:
            name:
              blank: "can't be blank"

它将在错误区域返回:name can't be blank

<% @user.errors.each do |error| -%>
  <p><%= error %></p>
<% end -%>

我要创建的下一步是像这样重命名 name 属性(和其他属性)(这是行不通的):

tr:
  attributes:
    user:
      name: "Real name"

验证后出现此错误:Real name can't be blank

所以我应该在哪里设置属性名称以在错误消息中翻译它们

【问题讨论】:

    标签: ruby-on-rails ruby internationalization locale ruby-on-rails-3


    【解决方案1】:

    试试这个:

    tr:
        activerecord:
            attributes:
                modelname:
                    attributename: "translation"
    

    modelname 替换为您的模型名称,将 attributename 替换为您要为其提供翻译的属性的名称,此处为 name

    【讨论】:

    • 没有反应。我尝试使用 labels.model.attributeshelpers.model.attributes 等 - 没有结果
    • 我发现,Rails 3 在错误列表中默认不使用 human_attribute_name。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多