webpack/examples/i18n
Tobias Koppers cc4f8345fa updated examples 2013-05-08 15:36:54 +02:00
..
README.md updated examples 2013-05-08 15:36:54 +02:00
build.js added i18n example, fixed error/warning bug 2013-02-19 12:48:17 +01:00
de.json added i18n example, fixed error/warning bug 2013-02-19 12:48:17 +01:00
example.js added i18n example, fixed error/warning bug 2013-02-19 12:48:17 +01:00
template.md added i18n example, fixed error/warning bug 2013-02-19 12:48:17 +01:00
webpack.config.js added i18n example, fixed error/warning bug 2013-02-19 12:48:17 +01:00

README.md

example.js

console.log(__("Hello World"));
console.log(__("Missing Text"));

webpack.config.js

var I18nPlugin = require("i18n-webpack-plugin");
module.exports = {
	plugins: [
		new I18nPlugin(
			require("./de.json") // or pass null to use defaults
		)
	]
}

I recommend to use new I18nPlugin(null) for development and write a small script that generates bundles for every language

de.json

{
	"Hello World": "Hallo Welt"
}

js/output.js

/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
/******/ 	
/******/ 	// The require function
/******/ 	function require(moduleId) {
/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId])
/******/ 			return installedModules[moduleId].exports;
/******/ 		
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			exports: {},
/******/ 			id: moduleId,
/******/ 			loaded: false
/******/ 		};
/******/ 		
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(null, module, module.exports, require);
/******/ 		
/******/ 		// Flag the module as loaded
/******/ 		module.loaded = true;
/******/ 		
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/ 	
/******/ 	// The bundle contains no chunks. A empty chunk loading function.
/******/ 	require.e = function requireEnsure(_, callback) {
/******/ 		callback.call(null, require);
/******/ 	};
/******/ 	
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	require.modules = modules;
/******/ 	
/******/ 	// expose the module cache
/******/ 	require.cache = installedModules;
/******/ 	
/******/ 	
/******/ 	// Load entry module and return exports
/******/ 	return require(0);
/******/ })
/************************************************************************/
/******/ ({
/******/ // __webpack_public_path__
/******/ c: "",

/***/ 0:
/*!********************!*\
  !*** ./example.js ***!
  \********************/
/***/ function(module, exports, require) {

	console.log("Hallo Welt");
	console.log("Missing Text");

/***/ }
/******/ })

Info

Uncompressed

Hash: a8c44c574f5009973fbd963c4710f86d
Version: webpack 0.10.0-beta6
Time: 25ms
    Asset  Size  Chunks             Chunk Names
output.js  1741       0  [emitted]  main       
chunk    {0} output.js (main) 64 [rendered]
    [0] ./example.js 64 [built] {0}

ERROR in ./example.js
Missing localization: Missing Text

Minimized (uglify-js, no zip)

Hash: a8c44c574f5009973fbd963c4710f86d
Version: webpack 0.10.0-beta6
Time: 48ms
    Asset  Size  Chunks             Chunk Names
output.js   308       0  [emitted]  main       
chunk    {0} output.js (main) 64 [rendered]
    [0] ./example.js 64 [built] {0}

ERROR in ./example.js
Missing localization: Missing Text