Git Product home page Git Product logo

node-translate's Introduction

Node Translate Build Status

A translation library for NodeJS that wraps node-polyglot

Installation

To build a local version for use or development:

git clone [email protected]:thestonefox/node-translate.git
cd node-translate
npm install

Installing as a node module:

npm install node-translate --save

Example

Look at the example.js file to see a simple example of the library.

Run it with npm start

For more examples of the format of the locale files, look in ./locales/

module.exports = {
  "title": "Hello, World"
}

Usage

Create a new instance of the i18n library.

var i18n = require('node-translate');

Require the relevant locale files in a associative array with the key being the name of the locale and the value being the output of the respective locale file.

i18n.requireLocales({
  'en-gb': require('./locales/en-gb'),
  'fr': require('./locales/fr')
});

Set the initial locale to use by providing the locale name. The first specified required locale is used as the current locale by default.

i18n.setLocale('en-gb');

Now simply call the translation method with the key to translate.

i18n.t('title');

The t method is compatible with polyglot so takes an optional second parameter for parsing variables into the translation string.

i18n.t('title', {name: "string"})

Chaining setters is also permitted.

i18n.requireLocales({'de': require('./locales/de')}).setLocale('de');

Running Tests

To run the Jest tests just type:

npm test

node-translate's People

Contributors

thestonefox avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.