https://github.com/component/t
translation utility
https://github.com/component/t
Last synced: 8 months ago
JSON representation
translation utility
- Host: GitHub
- URL: https://github.com/component/t
- Owner: component
- Created: 2012-09-12T22:23:39.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2014-03-17T14:45:29.000Z (about 12 years ago)
- Last Synced: 2025-08-09T16:58:38.830Z (8 months ago)
- Language: JavaScript
- Size: 204 KB
- Stars: 16
- Watchers: 9
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
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