Skip to content

internationalisation (i18n) for node.js the easy way (incl. clientside usage)

License

Notifications You must be signed in to change notification settings

htang555/i18next-node

 
 

Repository files navigation

Introduction

Build Status

Project goal is to provide the same easy way to translate a website on serverside like in i18next on the clientside:

  • Translation inside your server code or template
  • loading resourcefiles
  • update resourcefiles with missing strings
  • interpolation, plurals, nesting or resources
  • serve the same resources to the clientside

installation

npm install i18next

usage

First require the module and init i18next:

var i18next = require('i18next');
i18next.init(); // for options see i18next-node gh-page

Register the express middleware, so we can check current language settings:

// Configuration
app.configure(function() {
    app.use(express.bodyParser());
    app.use(i18next.handle);
    app.use(app.router);

    [...]
});

Register AppHelper so you can use the translate function in your template:

i18next.registerAppHelper(app)

Now you can (depending on your template language) do something like this in you template:

// sample in jade
body
    span= t('app.name')

To serve the clientside script and needed routes for resources and missing keys:

i18next.serveClientScript(app)
    .serveDynamicResources(app)
    .serveMissingKeyRoute(app);

now you can add the script to you page and use i18next on the client like on the server:

script(src='i18next/i18next.js', type='text/javascript')

$.i18n.init([options], function() { 
    $('#appname').text($.t('app.name'));
});

for more information on clientside usage have a look at i18next

sample

License

Copyright (c) 2014 Jan Mühlemann

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

internationalisation (i18n) for node.js the easy way (incl. clientside usage)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%