Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

i18njs

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

i18njs

A simple i18n for Javascript with a templating feature.

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
119
increased by4.39%
Maintainers
1
Weekly downloads
 
Created
Source

i18njs

A simple i18n for Javascript with a templating feature.

Installation

Either


npm install --save i18njs

or


bower install --save i18njs

Usage

After importing it var i18n = require('i18njs');

Add locales

By default, language is set to en.


var en = {
	'hello_world': {
		'hello': 'Hello',
		'world': 'World'
	}
};
// i18n.add(language, namespace [optional], locales);
i18n.add('en', 'first_test', en);

Change language


i18n.lng = 'fr';

Get basic localized string


// i18n.get(key, data, options);
i18n.get('first_test.hello_world.hello'); // Hello

Get templated string

It uses a basic templating engine, the same as underscore.

It works in the form of {{=interpolate}}, {{evaluate}} or {{-escape}} :


var en = {
	'st': '{{=interpolate}} {{for(var i = 0, max = 1; i < max; i += 1) {}}to{{}}} {{-escape}}'
};

var data = {
	'interpolate': 'Hello',
	'escape': '\'<the>\' `&` "World"'
};

i18n.add('en', en);
var st = i18n.get('st', data);
// "Hello  to  &#x27;&lt;the&gt;&#x27; &#x60;&amp;&#x60; &quot;World&quot;"

You can also change delimeters by passing the third options arguments


var st = i18n.get('st', data, {
	evaluate: /<%([\s\S]+?)%>/g;
    interpolate: /<%=([\s\S]+?)%>/g;
    escape: /<%-([\s\S]+?)%>/g;
});

Will result in <%=interpolate%>, <%evaluate%> or <%-escape%>

Keywords

FAQs

Package last updated on 06 Apr 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc