【问题标题】:Rails 3.1 nested forms validation translationRails 3.1 嵌套表单验证翻译
【发布时间】:2012-03-12 10:44:42
【问题描述】:

我正在尝试使用 YAML 别名翻译验证错误消息

ru:
  activerecord:
    models:
      user: Пользователь
      profile: Профиль
    attributes:
      profile: &profile_attributes
        name: "Отображаемое имя"
        ya_login: 'Логин на Яндексе'
        description: 'Описание'
      user:
        password: Пароль
        profile_fields:
          <<: *profile_attributes

或者没有 YAML 别名,像这样:

ru:
  activerecord:
    models:
      user: Пользователь
      profile: Профиль
    attributes:
      profile: &profile_attributes
        name: "Отображаемое имя"
        ya_login: 'Логин на Яндексе'
        description: 'Описание'
      user:
        password: Пароль
        profile_fields:
          name: "Отображаемое имя"
          ya_login: 'Логин на Яндексе'
          description: 'Описание

但我收到:

您的个人资料登录 не может быть пустым

哪里会出错?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3.1 nested-forms


    【解决方案1】:

    我发现了这个https://rails.lighthouseapp.com/projects/8994/tickets/5665-label-form-helper-and-i18n-with-nested-attributes-does-not-work,它帮助我了解了如何翻译嵌套表单。

    表格示例:

    form_for(@post) do
      fields_for(:author) do
        label :name
      end
    end
    

    这对我不起作用:

    fr:
      activerecord:
        attributes:
          author:
            name: Nom
    

    但这有效:

    fr:
      helpers:
        label:
          post[author_attributes]:
            name: Nom
    

    如果你想保持干燥:

    fr:
      activerecord:
        attributes:
          post:
            [...]
          author: &author_attributes
            name: Nom
    
      helpers:
        label:
          record[author_attributes]:
            <<: *author_attributes
    

    我发现了几个与嵌套表单 i18n 相关的问题/cmets:

    https://github.com/rails/rails/pull/3441

    https://github.com/rails/rails/commit/c19bd4f88ea5cf56b2bc8ac0b97f59c5c89dbff7

    https://github.com/rails/rails/issues/1869

    他们应该改进有关如何翻译嵌套表单的文档。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 2011-10-11
    • 2016-05-21
    • 1970-01-01
    • 2014-09-26
    • 2017-03-02
    相关资源
    最近更新 更多