human_attribute_name and translation files in rails

a 夏天 提交于 2019-12-11 10:46:56

问题


I am running a site w/ English and Spanish translation files, with the English as the default.

Using translations such as:

en:
  tenants:
    about: "About" 

to

es:
  tenants:
    about: "Acera" 

Using

t "tenants.about"

Works without issue and reads properly from either the en.yml and es.yml files when appropriate.

However, when trying to use the human_attribute_name property to pull model attributes from another section of the spanish es.yml file, the values are not being read.

So something like

Job.human_attribute_name(:title)

Returns "title" instead of "Título".

The portion of the same es.yml file with the humanized attributes is as follows:

 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"

Any insight would be appreciated.


回答1:


Wow - super annoying.

This was at the bottom of the long es.yml translation file from github: 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

Which was overriding my activerecord: declaration at the top of the file.

Not the best location considering it's a 200+ line file, but shame on me for not reading the whole thing. Hope this helps someone.




回答2:


I think the 'es:' is missing, or the indentation is not correct. The " are not necessary :

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


来源:https://stackoverflow.com/questions/13685401/human-attribute-name-and-translation-files-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!