This repository has been archived by the owner. It is now read-only.
i18n loader module for webpack - UNMAINTAINED
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
locale
sync
README.md
choose.loader.js
concat.loader.js Initial commit May 18, 2012
index.js
index.loader.js
merge.loader.js
package.json

README.md

i18n loader for webpack

Usage

./colors.json

{
	"red": "red",
	"green": "green",
	"blue": "blue"
}

./de-de.colors.json

{
	"red": "rot",
	"green": "grün"
}

call it

// assuming our locale is "de-de-berlin"
var locale = require("i18n!./colors.json");

// wait for ready, this is only required once for all locales in a web app
// because all locales of the same language are merged into one chuck
locale(function() {
	console.log(locale.red); // prints rot
	console.log(locale.blue); // prints blue
});

options

You should tell the loader about all your locales, if you want to load them once and than want to use them synchronous.

{
	"i18n": {
		"locales": [
			"de",
			"de-de",
			"fr"
		],
		// "bundleTogether": false
		// this can disable the bundling of locales
	}
}

alternative calls

require("i18n/choose!./file.js"); // chooses the correct file by locale,
					// but it do not merge the objects
require("i18n/concat!./file.js"); // concatinate all fitting locales
require("i18n/merge!./file.js"); // merges the resulting objects
					// ./file.js is excuted while compiling
require("i18n!./file.json") == require("i18n/merge!json!./file.json")

Don't forget to polyfill require if you want to use it in node. See webpack documentation.

License

MIT (http://www.opensource.org/licenses/mit-license.php)