gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 06:10:41 25 4
gpt4 key购买 nike

翻译 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 的引擎的一部分时,同样会被放入 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

关于ruby-on-rails - 如何翻译 Rails 引擎的模型和属性名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14654447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com