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

rtranslation

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rtranslation

Very simple translation module.

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

rTranslation

Very simple translation module for Node.js

Installation

npm install --save rtranslation

Usage

Setting up

To set up rTranslation you have to use this:

GLOBAL.lang = require("rtranslation")(options);

Options object:

var options = {
  //default language, not required but recommended
  language: "en_EN"
  //string to return if passed key is wrong, by defoult key will be returned
  wrong: "undefined"
}

Loading translations

lang.loadTranslationFromFile(file, callback);
lang.loadTranslationFromFileSync(file);
lang.loadTranslation(language, object, callback);
  • file - (String, required) path to file
  • language - (String, required) language of this translation
  • object - (Object, required) object with translation
  • callback(error) - (Function, required) callback, if everythink went fine error==null

Getting translation

lang.loadTranslation(key, language);
lang.t(key, language);
  • key - (String, required) key in format "aaa.bbb.ccc..."
  • language - (String, optional) if not set default language will be used

Example

Using async module for loading multiple files

var async = require('async');

GLOBAL.lang = require("rtranslation")({
	language: "pl_PL",
	wrong: "undefined"
});

async.map(['pl.json','en.json'], lang.loadTranslationFromFile, function(err){
	if(err) throw err;

	console.log(lang.translation);

	console.log(lang.t("test"));
	console.log(lang.t("test", "en_EN"));

	console.log(lang.t("a.b.c.d"));
	console.log(lang.t("a.b.c.d", "en_EN"));

	console.log(lang.t("a.b.text"));
	console.log(lang.t("a.b.text", "en_EN"));

	//wrong keys
	console.log("Wrong keys:");
	console.log(lang.t("z"));
	console.log(lang.t("a.somethink"));
	console.log(lang.t("a.b.text.d"));
	console.log(lang.t("a.b.c.d.e"));
	console.log(lang.t("a.b"));

});

Keywords

translation

FAQs

Package last updated on 01 Mar 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