Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andrepolischuk/translate-text
Translate function with templates precompiling and helpers
https://github.com/andrepolischuk/translate-text
i18n internationalization intl translate translation
Last synced: 7 days ago
JSON representation
Translate function with templates precompiling and helpers
- Host: GitHub
- URL: https://github.com/andrepolischuk/translate-text
- Owner: andrepolischuk
- License: mit
- Created: 2017-11-23T15:24:37.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-19T20:05:10.000Z (over 3 years ago)
- Last Synced: 2024-04-23T13:46:45.377Z (7 months ago)
- Topics: i18n, internationalization, intl, translate, translation
- Language: JavaScript
- Size: 34.2 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# translate-text [![Build Status][travis-image]][travis-url]
> Translate function with templates precompiling and helpers
## Install
```sh
npm install --save translate-text
```## Usage
```js
import createTranslate from 'translate-text'
import pluralize from 'numd'const translation = {
hello: 'Hello',
echo: 'You say: $1',
more: {
age: 'I\'m a (pluralize $1|year|years) old'
},
greeting: 'I\m $name and I\'m (pluralize $age|year|years) old'
}const translate = createTranslate(translation, {pluralize})
translate('hello') // Hello
translate('echo', 'Foo') // You say: Foo
translate('more.age', 25) // I'm a 25 years old
translate('greeting', {
name: 'John Smith',
age: 25
}) // I'm John Smith and I'm 25 years old
```## API
### createTranslate(translation[, helpers])
Compile templates and return translate function.
#### translation
Type: `object`
Translation templates.
#### helpers
Type: `object`
Helper functions that are used in templates.
### translate(key[, ...args])
#### key
Type: `string`
Template key.
#### args
Type: `...any`
Arguments to insert into the template.
## Related
* [react-translate-text][react-translate-text] — React higher-order component for text translation
## License
MIT
[travis-url]: https://travis-ci.org/andrepolischuk/translate-text
[travis-image]: https://travis-ci.org/andrepolischuk/translate-text.svg?branch=master[react-translate-text]: https://github.com/andrepolischuk/react-translate-text