rails中的human_attribute_name和翻译文件 [英] human_attribute_name and translation files in rails

查看:161
本文介绍了rails中的human_attribute_name和翻译文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

使用翻译,例如:

en:
  tenants:
    about: "About" 

es:
  tenants:
    about: "Acera" 

使用

t "tenants.about"

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

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

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

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.

类似

Job.human_attribute_name(:title)

返回标题",而不是Título".

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

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

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.

推荐答案

哇-超级烦人.

这是来自github的长es.yml翻译文件的底部:

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

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

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

考虑到它是200多个行文件,这不是最佳位置,但是由于我看不懂整个内容而感到羞耻.希望这对某人有帮助.

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.

这篇关于rails中的human_attribute_name和翻译文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆