Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dbtek/ipret
Micro i18n library for node and browser. Translate your app with strings already there.
https://github.com/dbtek/ipret
i18n js l10n lightweight micro multilingual translation
Last synced: about 3 hours ago
JSON representation
Micro i18n library for node and browser. Translate your app with strings already there.
- Host: GitHub
- URL: https://github.com/dbtek/ipret
- Owner: dbtek
- License: mit
- Created: 2017-02-18T11:56:27.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-04-24T15:04:07.000Z (over 7 years ago)
- Last Synced: 2024-11-07T17:56:32.609Z (11 days ago)
- Topics: i18n, js, l10n, lightweight, micro, multilingual, translation
- Language: JavaScript
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Micro i18n library for node and browser. Ugly name comes from **i**nter**pret**. Use it to translate your app with strings already there.
### Install
```bash
$ npm install ipret -S
```### Usage
Below example can be used in node / browserify transform. For standalone usage include `dist/ipret.js`.
```js
const ipret = require('ipret')// add some translations
ipret.setStrings('tr', {
'Current password': 'Şimdiki şifre',
'New password': 'Yeni şifre',
'Change Password': 'Şifreyi Değiştir',
'Updated {0}': '{0} güncellendi',
'password': 'şifre'
})// set active lang
ipret.setLanguage('tr')_ = ipret.translate
// translate
_('Current password') // Şimdiki şifre
_('New password') // Yeni şifre
_('Updated {0}', 'password') // şifre güncellendi
_('New email address') // [Not translated string] New email address
```### API
#### setStrings(lang, strings)
Adds new language with translations. `lang` is language identifier (e.g. language code). `strings` is key-value translations.#### setLanguage(lang)
Activates a language to use in translations. `lang` is language identifier used before in `setStrings`.#### translate(str)
Translates given string if a translation for it is defined.#### getLanguage()
Returns active language identifier.#### getLanguages()
Returns all languages that are being used.### License
MIT### Author
İsmail Demirbilek - [@dbtek](https://twitter.com/dbtek)