ROR:大型翻译词典的 i18n 最佳实践
- 在国际化 Rails 应用程序时,在字典文件中组织/界定翻译范围的最佳实践方法是什么?
- 什么情况下应该使用变量插值?
- 每个短语都应该是它的条目吗?
- 有没有参加过 dhh 演讲的人可以透露一下 37signals 是如何分解他们的字典文件的?
使用 i18n gem 一个半月后,我们的 en.yml 文件变得巨大。使用范围界定有什么好处吗?我们希望字典更容易翻译并保持字典干燥,但希望考虑不同的时态并仍然利用我们有“您确定要删除此对象吗?”的情况 >,“您确定要将其标记为已完成吗?” 如“您确定要{{verb}}这个{{noun}}吗?”
- When internationalizing a rails app, what is the best practice way for organizing/scoping translations in the dictionary files?
- Under what circumstance should you use interpolations of variables?
- Should every phrase be it's entry?
- Is there anyone who participated in dhh's tolk who can shed some light on how 37signals broke up their dictionary files?
After a month and a half of using the i18n gem our en.yml file is becoming gigantic. Is there any benefit to using scoping? We want the dictionary to be easier to translate and to keep our dictionary DRY but want to take into consideration different tenses and still take advantage of situations where we have "Are you sure you want to delete this object?", "Are you sure you want to mark this as completed?" As "Are you sure you want to {{verb}} this {{noun}}?"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,在我们的组织中,我们使用 Rails 建议的默认目录结构完全翻译了它
,我们有我们的语言环境,然后我们有视图或模型
对于每个视图和模型,我们都创建了翻译,并且效果完美。
例如,在 HomeController#show 中我们使用:
并且它在views/home/{locale}.yml 中查找
它也适用于部分。
与上面的示例相同,但在“最新”部分中不确定
这是否正是您正在寻找的内容,但希望它有所帮助
Well, on our organization we completelly translated it with the default directory structures suggested by Rails
we have our locale and then we have either views or models
for every view and model we created the translations and it works perfectly.
for instance, in a HomeController#show we use:
and it looks in the views/home/{locale}.yml for the
It also works well with partials.
Same example as above, but in a 'latest' partial would be
Not sure if this is exactly what you were looking for, but hope it helps
一年前我也遇到了同样的问题,结果我构建了 t_t gem。它极大地减少了翻译文件中的重复量。有关更多详细信息,请参阅cheatsheet -
# Actions 将帮助您解决“您确定要 {{verb}} 这个 {{noun}} 吗?”
更新:
示例要点
I had the same problems year ago, as the result I've built t_t gem. It dramatically reduces amount of duplications in translation files. For more details look at cheatsheet - section
# Actions
will help you with "Are you sure you want to {{verb}} this {{noun}}?"UPDATED:
an example gist