翻译Rails项目的模型和属性名称的常用方法是:
MyModel.model_name.human
MyModel.human_attribute_name :myattribute
Run Code Online (Sandbox Code Playgroud)
或者,当您使用MyModel的表单时:
form.label :myattribute
Run Code Online (Sandbox Code Playgroud)
语言环境文件config/locales/en.yml
如下所示:
en:
activerecord:
models:
mymodel:
one: TranslatedMyModel
other: TranslatedMyModels
attributes:
mymodel:
myattribute: translated attribute
Run Code Online (Sandbox Code Playgroud)
这适用于常规的Rails项目.当相同的模型成为引擎调用的一部分时MyEngine
,同样的内容将放入config/locales/en.yml
引擎并以my_engine为前缀:
en:
my_engine:
activerecord:
models:
mymodel:
one: TranslatedMyModel
other: TranslatedMyModels
attributes:
mymodel:
myattribute: translated attribute
Run Code Online (Sandbox Code Playgroud)
my_engine前缀适用于各种翻译,除非尝试通过上述方法获取模型或属性名称.
我已经设置了一个新的Rails项目和引擎与Rails 3.2.11来测试,但没有成功.
有人知道如何使这项工作?
attributes model ruby-on-rails internationalization rails-engines