@hydrant/i18n-loader
v1.0.4
Published
Also see the demo (`npm run dev`) for examples.
Downloads
16
Readme
i18n Loader
Also see the demo (npm run dev
) for examples.
Use the loader as follows:
Single Language
import lang from './assets/lang/de-v1234.xml';
Result (lang
) looks something like this:
{
"testId": "testContent",
"framework_menu_title": "Menü"
}
Multi Language
const requireAll = require => require.keys().map(module => [module, require(module).default]);
const langs = requireAll(require.context('./assets/lang')).reduce((langs, item) => {
// pattern: ./lc-someshit-v1234.ext → lc-someshit
const key = item[0].match(/\.\/(.*)-v\d+/)[1];
return Object.assign(langs, { [key]: item[1] });
}, {});
Result (langs
) looks something like this:
{
"de": {
"testId": "testContent",
"framework_menu_title": "Menü"
},
"en": { ... }
}