Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/laurentpayot/intljulep
Super lightweight yet powerful i18n library
https://github.com/laurentpayot/intljulep
i18n internationalization light lightweight minimalist plural pluralization plurals tiny translate translations
Last synced: 3 months ago
JSON representation
Super lightweight yet powerful i18n library
- Host: GitHub
- URL: https://github.com/laurentpayot/intljulep
- Owner: laurentpayot
- License: mit
- Created: 2019-06-25T13:47:03.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-05-30T08:07:22.000Z (8 months ago)
- Last Synced: 2024-11-07T02:42:51.881Z (3 months ago)
- Topics: i18n, internationalization, light, lightweight, minimalist, plural, pluralization, plurals, tiny, translate, translations
- Language: JavaScript
- Homepage:
- Size: 42 KB
- Stars: 14
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# :tropical_drink: intljulep
Super lightweight yet powerful i18n library
[![dependencies](https://badgen.net/static/dependencies/None/green)](https://github.com/laurentpayot/intljulep/blob/main/package.json#L59)
![minified + brotlied size](https://badgen.net/static/minified%20brotli/218%20bytes/green)
![minified + zipped size](https://badgen.net/static/minified%20zip/259%20bytes/green)[![types](https://badgen.net/npm/types/intljulep)](https://github.com/laurentpayot/intljulep/blob/main/index.d.ts)
[![npm version](https://badgen.net/npm/v/intljulep)](https://www.npmjs.com/package/intljulep)
[![license](https://badgen.net/github/license/laurentpayot/intljulep)](https://github.com/laurentpayot/intljulep/blob/main/LICENSE)## Why
Only [20 lines of code](https://github.com/laurentpayot/intljulep/blob/main/intljulep.js) to get i18n with internal references (translations in your translations) and simple plurals such as in English or in French. No dependencies.
## NodeJS
### Installation
```bash
npm install intljulep
```### Import
```js
import { i18n } from 'intljulep'
```## Browser
Intljulep uses [ES modules](https://jakearchibald.com/2017/es-modules-in-browsers/), [widely supported](https://caniuse.com/es6-module) in browsers nowadays. Import the `i18n` function from the `intljulep.min.js` file. This file can be located in a CDN (example below) or copied in any directory of your website (for better performance and to be GDPR compliant, since you don’t have to connect to a third party server).```html
import { i18n } from 'https://cdn.jsdelivr.net/npm/[email protected]/intljulep.min.js'
```
## Usage
```js
i18n.addLocale('en', {
foo: "the bar",
plurals: {
msg: ["message", "messages"],
man: ["man", "men"],
woman: ["woman", "women"]
},
email: {
hey: "Hey!",
// Note the `@` prefix to use other translations in your translation
info: "Hi {name}. {@email.hey} You have {number} {@plurals.msg(number)}."
}
})
i18n.setLocale('en')i18n('foo') // "the bar"
i18n('email.baz') // "email.baz"
i18n('plurals.msg', 0) // "messages"
i18n('plurals.msg', 1) // "message"
i18n('plurals.msg', 2) // "messages"
i18n('plurals.msg', 3) // "messages"
i18n('email.info', { name: "Laurent", number: 0 }) // "Hi Laurent. Hey! You have 0 messages."
i18n('email.info', { name: "Laurent", number: 1 }) // "Hi Laurent. Hey! You have 1 message."
i18n('email.info', { name: "Laurent", number: 2 }) // "Hi Laurent. Hey! You have 2 messages."
i18n('email.info', { name: "Laurent", number: 3 }) // "Hi Laurent. Hey! You have 3 messages."i18n.addLocale('fr', {
foo: "le bar"
})
i18n.setLocale('fr')
i18n('foo') // "le bar"i18n.setLocale('en')
i18n('foo') // "the bar"
```Note that you don’t have to use the `plurals` key specifically as nothing is hardcoded. You could use a single character key like `s` for convenience:
```js
i18n.addLocale('en', {
s: {
msg: ["message", "messages"],
man: ["man", "men"],
woman: ["woman", "women"]
},
})
i18n.setLocale('en')i18n('s.man', 3) // "men"
```## License
[MIT](https://github.com/laurentpayot/intljulep/blob/main/LICENSE)
## Stargazers :heart:
[![Stargazers repo roster for @laurentpayot/intljulep](http://reporoster.com/stars/laurentpayot/intljulep)](https://github.com/laurentpayot/intljulep/stargazers)