https://github.com/serg-io/i18n
Internationalization using tagged template literals.
https://github.com/serg-io/i18n
i18n internationalization l10n localization template-literals translation
Last synced: 5 months ago
JSON representation
Internationalization using tagged template literals.
- Host: GitHub
- URL: https://github.com/serg-io/i18n
- Owner: serg-io
- License: mit
- Created: 2019-01-15T15:40:51.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-16T21:39:51.000Z (over 7 years ago)
- Last Synced: 2025-06-25T02:38:35.706Z (12 months ago)
- Topics: i18n, internationalization, l10n, localization, template-literals, translation
- Language: HTML
- Homepage:
- Size: 432 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Introduction ##
This library allows you to use [tagged template literals](
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_templates)
in your source code to generate content for different languages. This library provides the following
functions:
* **`load`**: This function can be used to load definitions.
* **`i18n`**: Template literals can be tagged with `i18n` to retrieve definitions that have been
previously loaded using the `load` function.
## Installation ##
```bash
npm install @serg.io/i18n
```
## Example ##
You must first load the text definitions:
```javascript
import i18n, { load } from 'path/to/src/i18n.js';
// Load text definitions.
load({
user: {
firstName: 'First name',
lastName: 'Last name',
},
submit: 'Submit',
});
```
Once your text definitions have been loaded, you can tag template literals using `i18n`. For
instance, the following example will change the `innerText` of the `button` with the string
"Submit":
```javascript
import i18n, { load } from 'path/to/src/i18n.js';
// Find the submit button.
const button = document.querySelector('button[type="submit"]');
// Change its text using i18n.
button.innerText = i18n`submit`;
```
## License ##
[MIT](https://github.com/serg-io/i18n/blob/master/LICENSE).