【问题标题】:human_attribute_name and translation files in railsrails 中的human_attribute_name 和翻译文件
【发布时间】:2012-12-03 14:34:24
【问题描述】:

我正在运行一个带有英语和西班牙语翻译文件的网站,默认使用英语。

使用以下翻译:

en:
  tenants:
    about: "About" 

es:
  tenants:
    about: "Acera" 

使用

t "tenants.about"

正常工作,并在适当时从 en.yml 和 es.yml 文件中正确读取。

但是,当尝试使用 human_attribute_name 属性从西班牙语 es.yml 文件的另一部分中提取模型属性时,不会读取这些值。

类似

Job.human_attribute_name(:title)

返回“title”而不是“Título”。

同一es.yml文件中人性化属性部分如下:

 es:
  tenants:
    about: "Acerca"
  activerecord:
    attributes:
      job:
        title: "Título de la oferta de trabajo"
        location: "Localización de la oferta de trabajo"
        job_type: "Tipo de trabajo"
        description: "Descripción"

任何见解将不胜感激。

【问题讨论】:

    标签: ruby-on-rails ruby localization internationalization


    【解决方案1】:

    哇——超级烦人。

    这是来自 github 的长 es.yml 翻译文件的底部:https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale

    # remove these aliases after 'activemodel' and 'activerecord' namespaces are removed from 
    Rails repository
      activemodel:
        errors:
          <<: *errors
      activerecord:
        errors:
          <<: *errors
    

    覆盖了我的 activerecord: 文件顶部的声明。

    考虑到它是一个超过 200 行的文件,这不是最佳位置,但我很遗憾没有阅读整个内容。希望这对某人有所帮助。

    【讨论】:

      【解决方案2】:

      我认为缺少“es:”,或者缩进不正确。 " 不是必需的:

      es: 
        activerecord:
          attributes:
            job:
              title: Título
      

      【讨论】:

      • 我认为这不是问题,但我添加了完整的 es.yml 以帮助澄清
      猜你喜欢
      • 1970-01-01
      • 2011-04-07
      • 1970-01-01
      • 1970-01-01
      • 2019-02-11
      • 1970-01-01
      • 2022-09-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多