Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/component/t
translation utility
https://github.com/component/t
Last synced: 12 days ago
JSON representation
translation utility
- Host: GitHub
- URL: https://github.com/component/t
- Owner: component
- Created: 2012-09-12T22:23:39.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-03-17T14:45:29.000Z (almost 11 years ago)
- Last Synced: 2024-04-14T01:00:45.788Z (9 months ago)
- Language: JavaScript
- Size: 204 KB
- Stars: 16
- Watchers: 11
- Forks: 6
- Open Issues: 1
-
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