|
| 1 | + |
| 2 | +# example.js |
| 3 | + |
| 4 | +``` javascript |
| 5 | +console.log(__("Hello World")); |
| 6 | +console.log(__("Missing Text")); |
| 7 | +``` |
| 8 | + |
| 9 | +# webpack.config.js |
| 10 | + |
| 11 | +``` javascript |
| 12 | +var I18nPlugin = require("i18n-webpack-plugin"); |
| 13 | +module.exports = { |
| 14 | + plugins: [ |
| 15 | + new I18nPlugin( |
| 16 | + require("./de.json") // or pass null to use defaults |
| 17 | + ) |
| 18 | + ] |
| 19 | +} |
| 20 | +``` |
| 21 | + |
| 22 | +> I recommend to use `new I18nPlugin(null)` for development |
| 23 | +> and write a small script that generates bundles for every language |
| 24 | +
|
| 25 | +# de.json |
| 26 | + |
| 27 | +``` javascript |
| 28 | +{ |
| 29 | + "Hello World": "Hallo Welt" |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +# js/output.js |
| 34 | + |
| 35 | +``` javascript |
| 36 | +/******/ (function webpackBootstrap(modules) { |
| 37 | +/******/ var installedModules = {}; |
| 38 | +/******/ function require(moduleId) { |
| 39 | +/******/ if(installedModules[moduleId]) |
| 40 | +/******/ return installedModules[moduleId].exports; |
| 41 | +/******/ var module = installedModules[moduleId] = { |
| 42 | +/******/ exports: {}, |
| 43 | +/******/ id: moduleId, |
| 44 | +/******/ loaded: false |
| 45 | +/******/ }; |
| 46 | +/******/ modules[moduleId].call(null, module, module.exports, require); |
| 47 | +/******/ module.loaded = true; |
| 48 | +/******/ return module.exports; |
| 49 | +/******/ } |
| 50 | +/******/ require.e = function requireEnsure(chunkId, callback) { |
| 51 | +/******/ callback.call(null, require); |
| 52 | +/******/ }; |
| 53 | +/******/ require.modules = modules; |
| 54 | +/******/ require.cache = installedModules; |
| 55 | +/******/ return require(0); |
| 56 | +/******/ })({ |
| 57 | +/******/ c: "", |
| 58 | + |
| 59 | +/***/ 0: |
| 60 | +/*!********************!*\ |
| 61 | + !*** ./example.js ***! |
| 62 | + \********************/ |
| 63 | +/***/ function(module, exports, require) { |
| 64 | + |
| 65 | + console.log("Hallo Welt"); |
| 66 | + console.log("Missing Text"); |
| 67 | + |
| 68 | +/***/ } |
| 69 | +/******/ }) |
| 70 | + |
| 71 | +``` |
| 72 | + |
| 73 | +# Info |
| 74 | + |
| 75 | +## Uncompressed |
| 76 | + |
| 77 | +``` |
| 78 | +Hash: 6eb19a8e6a58c779abfd201110649331 |
| 79 | +Time: 17ms |
| 80 | + Asset Size Chunks Chunk Names |
| 81 | +output.js 989 0 main |
| 82 | +chunk {0} output.js (main) 64 |
| 83 | + [0] ./example.js 64 [built] {0} |
| 84 | +
|
| 85 | +ERROR in ./example.js |
| 86 | +Missing localization: Missing Text |
| 87 | +``` |
| 88 | + |
| 89 | +## Minimized (uglify-js, no zip) |
| 90 | + |
| 91 | +``` |
| 92 | +Hash: 6eb19a8e6a58c779abfd201110649331 |
| 93 | +Time: 51ms |
| 94 | + Asset Size Chunks Chunk Names |
| 95 | +output.js 308 0 main |
| 96 | +chunk {0} output.js (main) 64 |
| 97 | + [0] ./example.js 64 [built] {0} |
| 98 | +
|
| 99 | +ERROR in ./example.js |
| 100 | +Missing localization: Missing Text |
| 101 | +``` |
0 commit comments