在 Rails 中实现全球化
虽然我有用英语开发 Rails 应用程序的经验,但在处理全球化方面我是一张白纸,所以如果我的问题“没有意义”,请不要向我开枪:)
我被要求添加我正在开发的 Rails 应用程序的一部分的多语言功能。最初只有两种语言:法语和德语。目前将要翻译的内容(现在是英语)是使用部分内容呈现的,因此我有点倾向于使用不同语言创建部分内容,然后根据用户的语言选择调用相关部分 - 您会推荐这个吗方法?
虽然对于这个特定目的来说,它似乎是一个重量级的解决方案,但我也在研究 Rails Globalize 插件。如果我着眼于长期收益,这似乎很有吸引力,就像稍后我被要求翻译整个应用程序一样。
对于处理 Rails 全球化的正确结构化方法有什么见解吗?
非常感谢
While I have experience developing Rails apps in English, I am a blank slate when it comes to handling globalization, so please don't shoot me in the head if my question 'doesn't make sense' :)
I have been asked to add multi language feature to a part of a Rails app that I am working on. Initially its only going to be 2 languages, French and German. The content that will be translated (which is in English now) is rendered using partials at the moment hence I am getting a bit inclined on creating partials with different languages and then based on the users language selection call the relevant partial - Would you recommend this approach?
Although it seems a heavy weight solution for this particular purpose, but I am also looking at the Rails Globalize plugin. This seems to appeal if I look at the long term gains, something like what if later I am asked to translate the entire app.
Any insights on what would be a proper structured approach to handle globalization in Rails?
Many Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否看过自 2.2 起 Rails 本身中的 i18n(国际化)API ?它可以轻松地将您的语言翻译文件存储为 .yml 文件,例如 fr.yml 和 de.yml 或其他文件。它还逐步通过不同的方法使语言可通过浏览器首选项、URL、子域等进行访问。在 HTML 模板文件中,您使用符号来指定已翻译的字符串的键。至少在我的基本使用和测试中,它非常容易使用。
Have you had a look at the i18n (internationalization) API that is in Rails itself as of 2.2? It makes it easy to store your language translation files as .yml files, so a fr.yml and a de.yml or whatever. It also steps through different approaches of making languages accessible via browser prefs, or URLs, subdomains, etc. In your HTML template files you use symbols to specify the keys for the string you've translated. At least in my basic usage and testing, it was very easy to work with.
我更喜欢使用 translator 而不是 Rail 的 i18n,因为前者会自动处理“翻译范围”。我建议你看一下。
I preffer using translator instead of Rail's i18n, since the former handles "scoping of translation" automatically. I recommend you give it a look.
这是一篇关于如何使用 Ruby 的 GetText 进行本地化的精彩文章轨道应用程序。
This is a great article on how to use Ruby's GetText to localise you Rails App.