一个全功能的国际化翻译的JavaScript库:i18next

jopen 10年前

i18next是一个全功能,用于Web应用的国际化翻译的JavaScript库。运行在浏览器中,Node.js,rhino 和其他JavaScript运行时。i18next通过定义语言变量,页面编写私有标签,再绑定标签和语言变量,从而达到页面层国际化效果。

好处:

  1. support for variables
  2. support for nesting
  3. support for context
  4. support for multiple plural forms
  5. gettext support
  6. sprintf supported
  7. detect language
  8. graceful translation lookup
  9. jquery function
  10. get string or object tree
  11. get resourcefiles from server
  12. resource caching in browser
  13. post missing resources to server
  14. highly configurable
  15. custom post processing
  16. translation ui

使用示例:
page source:

<!DOCTYPE html>  <html>    <head>      <script type="text/javascript" src="[PATH]/jquery.js" /> // optional      <script type="text/javascript" src="[PATH]/i18next.js" />    </head>    <body>      <ul class="nav">        <li><a href="#" data-i18n="nav.home"></a></li>        <li><a href="#" data-i18n="nav.page1"></a></li>        <li><a href="#" data-i18n="nav.page2"></a></li>      </ul>    </body>  </html>

loaded resource file (locales/en/translation.json):

{    "app": {      "name": "i18next"    },    "nav": {      "home": "Home",      "page1": "Page One",      "page2": "Page Two"    }  }

javascript code:

i18n.init(function(t) {    // translate nav    $(".nav").i18n();      // programatical access    var appName = t("app.name");  });

项目主页:http://www.open-open.com/lib/view/home/1416017923195