加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 如何翻译Rails引擎的模型和属性名称?

发布时间:2020-12-17 03:04:41 所属栏目:百科 来源:网络整理
导读:翻译Rails项目的模型和属性名称的常用方法是: MyModel.model_name.humanMyModel.human_attribute_name :myattribute 或者,当您使用MyModel的表单时: form.label :myattribute 语言环境文件config / locales / en.yml如下所示: en: activerecord: models:
翻译Rails项目的模型和属性名称的常用方法是:

MyModel.model_name.human

MyModel.human_attribute_name :myattribute

或者,当您使用MyModel的表单时:

form.label :myattribute

语言环境文件config / locales / en.yml如下所示:

en:
  activerecord:
    models:
      mymodel:
        one: TranslatedMyModel
        other: TranslatedMyModels
  attributes:
    mymodel:
      myattribute: translated attribute

这适用于常规的Rails项目.当同一模型成为名为MyEngine的Engine的一部分时,同样的内容将被放入Engine的config / locales / en.yml中,并以my_engine为前缀:

en:
  my_engine:
      activerecord:
        models:
          mymodel:
            one: TranslatedMyModel
            other: TranslatedMyModels
      attributes:
        mymodel:
          myattribute: translated attribute

my_engine前缀适用于各种翻译,除非尝试通过上述方法获取模型或属性名称.

我已经设置了一个新的Rails项目和引擎与Rails 3.2.11来测试,但没有成功.

有人知道如何使这项工作?

解决方法

我在github上的Rails问题部分得到了帮助.这就是答案:

en:
  activerecord:
    models:
      'my_engine/mymodel':
        one: TranslatedMyModel
        other: TranslatedMyModels
    attributes:
      'my_engine/mymodel':
        myattribute: translated attribute

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读