https://github.com/b4rtaz/ultimate-i18n-js
Simplest ever I18N 1 KB library for HTML/JavaScript apps.
https://github.com/b4rtaz/ultimate-i18n-js
i18n i18n-js internationalization javascript l10n transaction
Last synced: 9 months ago
JSON representation
Simplest ever I18N 1 KB library for HTML/JavaScript apps.
- Host: GitHub
- URL: https://github.com/b4rtaz/ultimate-i18n-js
- Owner: b4rtaz
- License: mit
- Created: 2022-10-29T16:12:52.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-31T18:48:27.000Z (over 3 years ago)
- Last Synced: 2025-09-08T16:48:32.253Z (9 months ago)
- Topics: i18n, i18n-js, internationalization, javascript, l10n, transaction
- Language: TypeScript
- Homepage:
- Size: 139 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

# Ultimate I18n JS 🤯
[](https://actions-badge.atrox.dev/b4rtaz/ultimate-i18n-js/goto?ref=main) [](/LICENSE) [](https://npmjs.org/package/ultimate-i18n-js) [](https://twitter.com/b4rtaz)
Ultimate internationalization library for web applications.
* Super simple & easy.
* Less than 1KB (minified and gziped).
* 0 dependencies.
* SEO friendly (default language will be indexed).
* Automatic a user's language detection.
* It remembers a language change (uses local storage).
* JavaScript / TypeScript support.
* Support all modern browsers (it uses the [MutationObserver](https://caniuse.com/mutationobserver) internally).
#### 🤩 Online Examples
* [Basic](https://b4rtaz.github.io/ultimate-i18n-js/examples/static-web-app/basic.html)
* [Create Element](https://b4rtaz.github.io/ultimate-i18n-js/examples/static-web-app/create-element.html)
* [Document Write](https://b4rtaz.github.io/ultimate-i18n-js/examples/static-web-app/document-write.html)
* [Dynamic Text](https://b4rtaz.github.io/ultimate-i18n-js/examples/static-web-app/dynamic-text.html)
* [Late Setup](https://b4rtaz.github.io/ultimate-i18n-js/examples/static-web-app/late-setup.html)
## 🚀 Use with Static HTML Web App
Set your default language code in the `html` tag.
```html
```
Add this library as **the first script** in your `` section.
```html
...
```
That's it! 🤯 Now you can add language attributes to any element on your page.
```html
Hello World
````
To change language call the `set` function.
```js
UltimateI18n.set('es');
```
```html
EN
ES
PL
```
➡ Check [examples for static HTML web apps](examples/static-web-app)
## 🚀 Use with Module Bundler
Install this package.
`npm install ultimate-i18n-js`
Set your default language code in the `html` tag.
```html
```
Call the `setup` method before your app start.
```ts
import * as UltimateI18n from 'ultimate-i18n-js';
UltimateI18n.setup();
```
That's it! 🤯 Now you can add dynamicaly content to your app.
```ts
document.addEventListener('DOMContentLoaded', () => {
document.getElementById('placeholder').innerHTML = `
I love red
`;
});
```
To change language call the `set` function.
```js
UltimateI18n.set('es');
```
➡ Check [examples for Webpack apps](examples/webpack-app)
## ⚒ API
* `UltimateI18n.set('es')` - Changes the current language.
* `UltimateI18n.get()` - Reads the current language.
* `UltimateI18n.setup()` - Initializes the library. This step is required only for a late setup.
* `UltimateI18n.isSupported` - Returns `true` if the library is enabled, otherwise `false`.
## 👷♂️ TODO
React and Angular is not supported yet.
The dynamic attribute change is not supported yet. The below code currently doesn't work properly.
```js
const season = document.getElementById('season');
season.innerHtml = 'Summer';
season.setAttribute('i18n-pl', 'Lato');
season.setAttribute('i18n-es', 'El verano');
```
Use the below approach instead. Basically you need to replace a whole element.
```js
document.getElementById('seasonContainer').innerHTML = `
Summer
`;
```
Or:
```js
const newSeason = document.createElement('h2');
newSeason.innerHtml = 'Summer';
newSeason.setAttribute('i18n-pl', 'Lato');
newSeason.setAttribute('i18n-es', 'El verano');
oldSeason.replaceWith(newSeason);
```
## 💡 License
This project is released under the MIT license.