t-component

tiny translation helper

t

tiny translation helper.

$ component install component/t

Return a translatable string, with optional substitutions keyed in object using language lang.

var t = require('t');
 
t('Hello');
// => "Hello" 
 
t('Hello {name}', { name: 'Tobi' });
// => "Hello Tobi" 

Get the current language code, for example "en".

Set language code.

Define translations, for example:

t.es = {
  'Hello {name}': 'Hola {name}'
};
 
t('Hello {name}', { name: 'Tobi' });
// => "Hello Tobi" 
 
t.lang('es');
t('Hello {name}', { name: 'Tobi' }).should.equal('Hola Tobi');
// => "Hola Tobi" 

License

MIT