Webpack i18n loader similar to require.js i18n plugin. The loader also support CommonJS module and .json
files, and more, .coffee
files.
npm install amdi18n-loader
First look at require.js i18n plugin's docs at here.
The language part is like this:
lang.js
zh-cn/lang.js
zh-hk/lang.js
lang.js:
define({
// root means the common language package
root:{
HELLO:'hello'
},
// we have the language packages below:
'zh-cn':true,
'zh-hk':true
});
zh-cn/lang.js example:
define({
// please note: no wrapper object here!
HELLO:'hello in zh-cn'
});
Then use it like this:
define([
'amdi18n!lang'
],function(amdi18n){
// By default, it will lookup `window._i18n.locale`,
// If not found, it will try to use the html[lang] attribute,
// For example: <html lang="en"> then language `en` was used,
// If nothing found, `root` was used.
// You can manully change the language by
// `amdi18n.init(language)`;
console.log(amdi18n.HELLO);
});
You can pass queries to enable or disable some langs.
// We use commonjs now. It matters nothing.
var lang = require('amdi18n?enable=[zh-cn]!');
// It's not ok to use zh-hk now!
lang.init('zh-hk');
The code below behaviors the same:
// We use commonjs now. It matters nothing.
// Notice: we use `|` to as separator,
// Because webpack will break the comma.
var lang = require('amdi18n?disable=[zh-hk|en-us]!');
// It's not ok to use zh-hk now!
lang.init('zh-hk');
It's ok to use both enable
and disable
, but if any one disables a lang, the lang will not be usable. You can decide which to use by the length of list.
- Fix: multi values in
enable
/disable
queries invalid. #10 - If a lang specified in
enable
, no longer required to specify in root.
- Fix: AMD lang file without factory function not working. #8
- Add
enable
anddisable
queries. #6 - Detect default language by html[lang] attribute. #7
- Rewrite the method that extract language definitions.
- Add testing & travis CI.
- Support
.coffee
language files. (By Mullerzs)
- Fix bug using in UMD mode. (By Rick)
- Fix bug on IE. (By Rick)
- Support load CommonJS module and json file. (By Rick)
- Auto init.
- First release.