attr-i18n
Internationalization through HTML attributes
A tiny client-side script which provides opinionated internationalization (i18n) capabilites to your website or web app.
Usage
npm i attr-i18n
# or
yarn add attr-i18n
import { AttrI18n } from 'attr-i18n';
const languages = ['English', 'हिन्दी', 'français'];
new AttrI18n(languages, {
attr: 'data-translation',
path: 'assets/translations',
debug: true,
togglerID: 'language-toggle',
defaultLang: languages[0]
});
Options
Name | Type | Required | Default | Description |
---|---|---|---|---|
attr |
string |
false | data-attr-i18n |
HTML attribute which contains the translation key |
path |
string |
false | assets/attr-i18n |
Path to the folder which contains the translation JSON file(s) |
debug |
boolean |
false | false |
Turns debug mode on/off |
togglerID |
string |
false | attr-i18n-toggler |
ID attribute for the language toggle HTML select element |
defaultLang |
string |
false | languages[0] |
The default language. If not provided, the first one from the array is used |