New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

node-translate

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-translate

A translation library for NodeJS that wraps node-polyglot

latest
Source
npmnpm
Version
0.0.4
Version published
Maintainers
1
Created
Source

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 git@github.com: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

Keywords

translate

FAQs

Package last updated on 15 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts