JavaScript的的I18n(国际化)的框架/客户机端使用库? [英] JavaScript I18n (internationalization) frameworks/libraries for client-side use?

查看:379
本文介绍了JavaScript的的I18n(国际化)的框架/客户机端使用库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前正在与Backbone.js的创建JavaScript应用,
我们需要它翻译或至少支持国际化(i18n)的未来。

We are currently creating a JavaScript application with backbone.js, and we need it translated or at least to support internationalization (I18n) in the future.

我一直在找了一圈,发现很多库,帮助;有些是相当简单的,其他人似乎过于复杂。我发现这些在过去的几个小时:

I've been looking around and found many libraries that help; Some are fairly simple where others seem overly complex. I found these in the past few hours:

  • i18next.js
  • jsperanto.js
  • jed.js
  • messageformat.js
  • jquery.i18n plugin
  • polyglot.js

有没有一些比较这些框架博客或网站?
我想看看其他人已经指出在任何这些库的利弊或陷阱。

Are there some blogs or sites that compare such frameworks? I would like to see if others already pointed out the pluses or pitfalls on any of these libraries.

我们创建了我们的应用程序模块的基础上 Require.js 所以如果有模块的支持,这绝对是一个加号。

We created our app module based on Require.js so if it has module support, that's definitely a plus.

另一个要求是设置​​地方初始化后,我们从Web服务获取数据后。我们不能说不定存储静态JSON文件,除了默认语言,与应用程序。翻译来自数据库,并需要通过Web服务发送到应用程序,所以我们需要通过JSON文件来设置本地化数据,而不是动态的。这至少在杰德和i18next和jsperanto在别人的支持,但最有可能也。在任何情况下,应用程序必须永远不会从执行被阻塞。

Another requirement would be setting the locale after initialization, after we fetch the data from a webservice. We can't store static JSON files, except maybe for a default language, with the app. The translations come from a database and need to be sent to the app via a webservice, so we need to set the localization data dynamically instead of through JSON files. This is supported at least in Jed and i18next and jsperanto, but most likely also in others. In any case the app must never be blocked from execution.

我寻求帮助决定哪些库西服最好的。

I'm asking for help deciding which library suits best.

东西我注意到,已经在杰德缺失,是提供一个优美的替代方案,当翻译是不是在现场词典present。杰德只是抛出一个错误,这是我感到不安。

Something I noticed that is already missing in Jed, is providing a graceful alternative when a translation is not present in the locale dictionary. Jed just throws an error, something I find disturbing.

我preFER的处理缺失的翻译更清洁的方式,可以提供一个默认字符串,打印键回到屏幕。此外,但绝对不是必需的,人们可以有类似的功能有i18next,张贴失踪翻译到一个web服务。虽然我们不需要这个,这是一个很好的功能。

I prefer a cleaner way of handling missing translations, either provide a default string, print the key back to the screen. Additionally, but definitely not required, one could have the feature like i18next has, to post missing translations to a webservice. Though we won't need this, it is a nice feature.

推荐答案

我最近一直在通过同样的困境,所以我打算先给你一些额外的事情要考虑:

I have recently been through the same dilemma so I am going first give you a few additional things to consider:


  1. 人人都会的消息的翻译,但这样做适当的复数形式是很难的。让你期待支持(包括未来的),并找出你的多元化将会变得多么复杂的语言列表。如果你确信你只会做一个复数形式语言,大多数图书馆将这样做。

  1. Everybody does message translation, but doing properly plural forms is hard. Make a list of the languages you expect to support (including the future ones) and find out how complex your pluralization will get. If you are certain that you will only do languages with one plural form, most of the libraries will do that.

我假设你有大的消息目录,多语言(如果不是这样,那么适当的国际化是不相关的,我认为你的应用程序)。这些目录最终获得复杂,必须通过翻译进行管理。对于国际化的标准是的gettext (的这里的简短摘要)。所有的工具到处管理翻译是为gettext的实现。没有期望您的翻译会在一些不起眼的格式来管理JSON文件。

I assume that you have large message catalogs, in multiple languages (if that's not the case then proper i18n is irrelevant I think to your app). These catalogs eventually get complicated and have to be managed by translators. The standard for i18n is gettext (here for a short summary). All the tools around to manage translations are done for gettext. Do not have the expectation that your translators are going to manage json files in some obscure format.

因此​​,在短暂的:你需要你的库要么负荷的.po或在服务器上生成的.mo文件,或有一个简单的方法来转换与服务器上的到库的JSON格式。这限制了你的选择,那些有翻译键和类似的gettext的MSGID的机制。这立即踢了出来,我i18next的实例。检查的其余部分。

So in brief: You will need your library to either load .po or .mo files generated on the server, or have an easy way to convert those on the server to the library's json format. That restricts your choices to those that have translation keys and mechanisms similar to gettext's msgid's. This immediately kicked out for me i18next for instance. Check for the rest.

Require.js不应该开车你的决定。即使库没有AMD兼容的,你会包好,并找到一种方法来异步加载目录的资源。

Require.js should not drive your decision. Even if the library is not AMD-compliant you will wrap it and also find a way to async-load your catalog resources.

现在,如果我不得不选择你所提到的那些之一,基于完整的,功能的支持,速度,易用性,我也不会在所有的想法。它必须是杰德。当时我做出我的选择杰德不存在,和沮丧我写了一个非常小(小于100lines)及快速的.po / JSON装载/分析器/消​​息工厂。我仍然使用它,它涵盖了我的小需求,但任何东西,最后我们有适当的js国际化大,这是杰德。

Now, if I had to pick one of the ones you mention, based on completeness, feature-support, speed, ease of use, I wouldn't have to think at all. It would have to be Jed. At the time I made my choice Jed did not exist, and frustrated I wrote a very minimal (<100lines) & fast .po/json loader/parser/message factory. I still use it, it covers my small needs, but for anything larger at last we have proper js i18n, and it's Jed.

更新
我看到了有关与问候丢失的钥匙杰德的缺点更新的问题。我presume这是因为通常与gettext的的所有的文本对应于的默认的语言的关键。然后生成的.po /翻译的.mo文件中缺少翻译只需在默认语言返回文本。

UPDATE I saw your updated question concerning shortcomings of Jed with regards to missing keys. I presume this is because typically with gettext all your text corresponds to a key in the default language. Then generated .po/.mo translation files missing the translation simply return the text in the default language.

这篇关于JavaScript的的I18n(国际化)的框架/客户机端使用库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆