在哪里存储模型属性值翻译
我有一个带有属性 payment_status 的模型发票。 payment_status 具有固定值 unpayed|partial_payed|paid 我想将其翻译存储在语言环境文件中。 我认为将它放在模型本地文件中会很好
de:
activerecord:
attributes:
payment_status: Zahlstatus
payment_status_values:
unpayed: offen
partial_payed: teilgezahlt
payed: ausgeglichen
,现在我可以获取最后一张发票的翻译后的 payment_status-value
I18n.t Invoice.last.payment_status , :scope => "activerecord.attributes.invoice.payment_status_values"
=> "offen"
对我来说,它看起来像输入了很多 sopes,是否有一个范围内的方法来获取翻译或者有更好的方法来做到这一点?
I have a model Invoice with attribute payment_status. payment_status has fixed values unpayed|partial_payed|payed that I want to store the translations for in a locale-file.
I thougt it would be good to have it in the model local-file
de:
activerecord:
attributes:
payment_status: Zahlstatus
payment_status_values:
unpayed: offen
partial_payed: teilgezahlt
payed: ausgeglichen
now I can get the translated payment_status-value for the last invoice like this
I18n.t Invoice.last.payment_status , :scope => "activerecord.attributes.invoice.payment_status_values"
=> "offen"
to me it looks like typing sopes a lot, is there maybe a scoped method to get the translation or a better way to do this at all?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们使用了 marcel 的 easy_enums 插件。我发现的最接近的是: https://github.com/mschuerig/easy_enums/
语法是这样的。然后您只存储范围标识符的最后一部分。
这达到你的目标了吗?
We used the easy_enums plugin from marcel. The closest I found was: https://github.com/mschuerig/easy_enums/
Syntax is like this. Then you store only last part of the scope identifier.
Does that hit your goal?