我正在使用 I18n 翻译构建 Rails 应用程序。
我有两个模型(博客和事件),共享相同的属性(标题、内容)。
在我的 I18n yml 文件中,如何避免为每个属性模型重复相同的键并共享它们?
我的实际代码摘录:
fr:
activerecord:
attributes:
blog:
title: Titre
content: Contenu
event:
title: Titre
content: Contenu
我还尝试将属性设置为默认值,但没有任何运气地删除了包装的模型键。
fr:
activerecord:
attributes:
title: Titre
content: Contenu
感谢您的帮助!
我的项目:
- rails 4.2.7.1
- ruby 2.3.0
最佳答案
回答了类似的问题here
你可以使用 yaml 别名来实现它
fr:
activerecord:
attributes:
blog: &title_content
title: Titre
content: Contenu
event: *title_content
引用yaml aliases了解更多信息。
关于ruby-on-rails - Rails - 如何避免重复相同的 i18n 属性翻译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40088600/