Ez Vanjs i18n is a simple and easy to use internationalization library for VanJs.
npm install ez-vanjs-i18n
Import the I18n class
import { I18n } from 'ez-vanjs-i18n';
Define a translation map
const translations = new Map([
['en', {
hello: 'Hello',
nested: {
world: 'World'
},
greeting: (params) => `Hello ${params.name}`
}],
['fr', {
hello: 'Bonjour',
nested: {
world: 'Monde'
},
greeting: (params) => `Bonjour ${params.name}`
}]
]);
Create an instance of the I18n class
const i18n = new I18n(translations, 'en');
Create a stateful translation variable
const greeting = i18n.t('greeting', { name: 'John' });
A full example of how to use Ez Vanjs i18n can be found in the example directory.