Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/component/t

translation utility
https://github.com/component/t

Last synced: 12 days ago
JSON representation

translation utility

Awesome Lists containing this project

README

        

# t

tiny translation helper.

## Installation

$ component install component/t

## API

### t(string, [object], [lang])

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

```js
var t = require('t');

t('Hello');
// => "Hello"

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

### t.lang()

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

### t.lang(code)

Set language `code`.

### t.CODE = object

Define translations, for example:

```js
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