1.1.0 • Published 8 years ago

spokesman v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 years ago

spokesman

Build Status Coverage Status

Straightforward library for translations and i18n

Install

You can get it on npm.

npm install spokesman --save

If you're not into package management, just download a ZIP file.

Setup

First, you need to import it or require it:

import Spokesman from 'spokesman';

Then, you need to instantiate it and passing a dictionary object optionally:

let spokesman = new Spokesman({
	pt: {
		'APPLE': 'maçã'
	},
	en: {
		'APPLE': 'apple'
	}
});

Usage

Adding dictionaries:

spokesman.addDictionary('fr', {
	'APPLE': 'pomme'
});

Using dictionaries and translating:

spokesman.useDictionary('pt');
spokesman.translate('APPLE'); // "maçã"

You can also use functions as the translations:

spokesman.addDictionary('fr', {
	'APPLE': function() {
		return 'pomme' + '!';
	}
});

spokesman.useDictionary('fr');

spokesman.translate('APPLE'); // "pomme!"

You can handle pluralisation by passing an array as the translations, and passing a second argument to the .translate() method.

spokesman.addDictionary('pt', {
	'APPLE': [
		'Sem maçãs',
		'1 maçã',
		'%s maçãs'
	]
});

spokesman.useDictionary('pt');

spokesman.translate('APPLE'); // if no count is passed, 1 is the default. "1 maçã" 
spokesman.translate('APPLE', 0); // "Sem maçãs"
spokesman.translate('APPLE', 1); // "1 maçã"
spokesman.translate('APPLE', 2); // "2 maçãs"
spokesman.translate('APPLE', 17); // "17 maçãs"

License

MIT © 2016

1.1.0

8 years ago

1.0.0

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago