ROR:大型翻译词典的 i18n 最佳实践

发布于 2024-09-18 18:50:35 字数 346 浏览 3 评论 0原文

  • 在国际化 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

禾厶谷欠 2024-09-25 18:50:35

好吧,在我们的组织中,我们使用 Rails 建议的默认目录结构完全翻译了它

,我们有我们的语言环境,然后我们有视图或模型
对于每个视图和模型,我们都创建了翻译,并且效果完美。

例如,在 HomeController#show 中我们使用:

t('.title')

并且它在views/home/{locale}.yml 中查找

{locale}:
  show:
    title:

它也适用于部分。
与上面的示例相同,但在“最新”部分中不确定

{locale}:
  latest:
    title:

这是否正是您正在寻找的内容,但希望它有所帮助

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:

t('.title')

and it looks in the views/home/{locale}.yml for the

{locale}:
  show:
    title:

It also works well with partials.
Same example as above, but in a 'latest' partial would be

{locale}:
  latest:
    title:

Not sure if this is exactly what you were looking for, but hope it helps

多孤肩上扛 2024-09-25 18:50:35

一年前我也遇到了同样的问题,结果我构建了 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文