Internationalization using tagged template literals.
load
: This function can be used to load definitions.
i18n
: Template literals can be tagged with i18n
to retrieve definitions that have beenload
function.bash
npm install @serg.io/i18n
javascript
import i18n, { load } from 'path/to/src/i18n.js';
// Load text definitions.
load({
user: {
firstName: 'First name',
lastName: 'Last name',
},
submit: 'Submit',
});
i18n
. ForinnerText
of the button
with the stringjavascript
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`;