Skip to content

Commit 9fd51c9

Browse files
committed
updated i18n example
1 parent 91c7426 commit 9fd51c9

5 files changed

Lines changed: 184 additions & 57 deletions

File tree

examples/build-common.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ var path = require("path");
1212
var extraArgs = "";
1313

1414
var targetArgs = global.NO_TARGET_ARGS?"":" ./example.js js/output.js"
15-
cp.exec("node ../../bin/webpack.js --display-reasons --display-chunks --display-origins --output-public-path \"js/\" -p "+extraArgs+targetArgs, function (error, stdout, stderr) {
15+
cp.exec("node ../../bin/webpack.js --display-reasons --display-chunks --display-modules --display-origins --output-public-path \"js/\" -p "+extraArgs+targetArgs, function (error, stdout, stderr) {
1616
if(stderr)
1717
console.log(stderr);
1818
if (error !== null)
1919
console.log(error);
2020
var readme = tc(fs.readFileSync(require("path").join(process.cwd(), "template.md"), "utf-8"), process.cwd(), stdout.replace(/[\r\n]*$/, ""), "min");
21-
cp.exec("node ../../bin/webpack.js --display-reasons --display-chunks --display-origins --output-public-path \"js/\" --optimize-occurence-order --output-pathinfo "+extraArgs+targetArgs, function (error, stdout, stderr) {
21+
cp.exec("node ../../bin/webpack.js --display-reasons --display-chunks --display-modules --display-origins --output-public-path \"js/\" --optimize-occurence-order --output-pathinfo "+extraArgs+targetArgs, function (error, stdout, stderr) {
2222
console.log(stdout);
2323
if(stderr)
2424
console.log(stderr);

examples/i18n/README.md

Lines changed: 147 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
This example uses the I18nPlugin in combination with the multi-compiler feature.
2+
3+
The `webpack.config.js` exports an array of all config combinations that should be compiled. In this example two different parameter for the I18nPlugin are used.
4+
5+
The I18nPlugin replaces every occurrence of the i18n function `__(...)` with a const string. i. e. `__("Hello World")` with `"Hello World"` resp. `"Hallo Welt"`.
6+
17

28
# example.js
39

@@ -9,19 +15,29 @@ console.log(__("Missing Text"));
915
# webpack.config.js
1016

1117
``` javascript
18+
var path = require("path");
1219
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+
var languages = {
21+
"en": null,
22+
"de": require("./de.json")
23+
};
24+
module.exports = Object.keys(languages).map(function(language) {
25+
return {
26+
name: language,
27+
entry: "./example",
28+
output: {
29+
path: path.join(__dirname, "js"),
30+
filename: language + ".output.js"
31+
},
32+
plugins: [
33+
new I18nPlugin(
34+
languages[language]
35+
)
36+
]
37+
};
38+
});
2039
```
2140

22-
> I recommend to use `new I18nPlugin(null)` for development
23-
> and write a small script that generates bundles for every language
24-
2541
# de.json
2642

2743
``` javascript
@@ -30,48 +46,47 @@ module.exports = {
3046
}
3147
```
3248

33-
# js/output.js
49+
# js/de.output.js
3450

3551
``` javascript
3652
/******/ (function(modules) { // webpackBootstrap
37-
/******/
3853
/******/ // The module cache
3954
/******/ var installedModules = {};
40-
/******/
55+
/******/
4156
/******/ // The require function
4257
/******/ function __webpack_require__(moduleId) {
58+
/******/
4359
/******/ // Check if module is in cache
4460
/******/ if(installedModules[moduleId])
4561
/******/ return installedModules[moduleId].exports;
46-
/******/
62+
/******/
4763
/******/ // Create a new module (and put it into the cache)
4864
/******/ var module = installedModules[moduleId] = {
4965
/******/ exports: {},
5066
/******/ id: moduleId,
5167
/******/ loaded: false
5268
/******/ };
53-
/******/
69+
/******/
5470
/******/ // Execute the module function
5571
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
56-
/******/
72+
/******/
5773
/******/ // Flag the module as loaded
5874
/******/ module.loaded = true;
59-
/******/
75+
/******/
6076
/******/ // Return the exports of the module
6177
/******/ return module.exports;
6278
/******/ }
63-
/******/
64-
/******/
79+
/******/
80+
/******/
6581
/******/ // expose the modules object (__webpack_modules__)
6682
/******/ __webpack_require__.m = modules;
67-
/******/
83+
/******/
6884
/******/ // expose the module cache
6985
/******/ __webpack_require__.c = installedModules;
70-
/******/
86+
/******/
7187
/******/ // __webpack_public_path__
7288
/******/ __webpack_require__.p = "js/";
73-
/******/
74-
/******/
89+
/******/
7590
/******/ // Load entry module and return exports
7691
/******/ return __webpack_require__(0);
7792
/******/ })
@@ -90,36 +105,125 @@ module.exports = {
90105
/******/ ])
91106
```
92107

108+
# js/en.output.js
109+
110+
``` javascript
111+
/******/ (function(modules) { // webpackBootstrap
112+
/******/ // The module cache
113+
/******/ var installedModules = {};
114+
/******/
115+
/******/ // The require function
116+
/******/ function __webpack_require__(moduleId) {
117+
/******/
118+
/******/ // Check if module is in cache
119+
/******/ if(installedModules[moduleId])
120+
/******/ return installedModules[moduleId].exports;
121+
/******/
122+
/******/ // Create a new module (and put it into the cache)
123+
/******/ var module = installedModules[moduleId] = {
124+
/******/ exports: {},
125+
/******/ id: moduleId,
126+
/******/ loaded: false
127+
/******/ };
128+
/******/
129+
/******/ // Execute the module function
130+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
131+
/******/
132+
/******/ // Flag the module as loaded
133+
/******/ module.loaded = true;
134+
/******/
135+
/******/ // Return the exports of the module
136+
/******/ return module.exports;
137+
/******/ }
138+
/******/
139+
/******/
140+
/******/ // expose the modules object (__webpack_modules__)
141+
/******/ __webpack_require__.m = modules;
142+
/******/
143+
/******/ // expose the module cache
144+
/******/ __webpack_require__.c = installedModules;
145+
/******/
146+
/******/ // __webpack_public_path__
147+
/******/ __webpack_require__.p = "js/";
148+
/******/
149+
/******/ // Load entry module and return exports
150+
/******/ return __webpack_require__(0);
151+
/******/ })
152+
/************************************************************************/
153+
/******/ ([
154+
/* 0 */
155+
/*!********************!*\
156+
!*** ./example.js ***!
157+
\********************/
158+
/***/ function(module, exports, __webpack_require__) {
159+
160+
console.log("Hello World");
161+
console.log("Missing Text");
162+
163+
/***/ }
164+
/******/ ])
165+
```
166+
93167
# Info
94168

95169
## Uncompressed
96170

97171
```
98-
Hash: 3bd94df73dbb84d38341
99-
Version: webpack 1.1.0
100-
Time: 48ms
101-
Asset Size Chunks Chunk Names
102-
output.js 1670 0 [emitted] main
103-
chunk {0} output.js (main) 65 [rendered]
104-
> main [0] ./example.js
105-
[0] ./example.js 65 {0} [built] [1 warning]
106-
107-
WARNING in ./example.js
172+
Hash: 11d340dd3b946937d5b60050649a7d8d87a49cc1
173+
Version: webpack 1.4.3
174+
175+
WARNING in (de) ./example.js
108176
Missing localization: Missing Text
177+
Child en:
178+
Hash: 11d340dd3b946937d5b6
179+
Version: webpack 1.4.3
180+
Time: 52ms
181+
Asset Size Chunks Chunk Names
182+
en.output.js 1634 0 [emitted] main
183+
chunk {0} en.output.js (main) 65 [rendered]
184+
> main [0] ./example.js
185+
[0] ./example.js 65 {0} [built]
186+
Child de:
187+
Hash: 0050649a7d8d87a49cc1
188+
Version: webpack 1.4.3
189+
Time: 39ms
190+
Asset Size Chunks Chunk Names
191+
de.output.js 1633 0 [emitted] main
192+
chunk {0} de.output.js (main) 65 [rendered]
193+
> main [0] ./example.js
194+
[0] ./example.js 65 {0} [built] [1 warning]
195+
196+
WARNING in ./example.js
197+
Missing localization: Missing Text
109198
```
110199

111200
## Minimized (uglify-js, no zip)
112201

113202
```
114-
Hash: 1ad5b360e07d437790fd
115-
Version: webpack 1.1.0
116-
Time: 107ms
117-
Asset Size Chunks Chunk Names
118-
output.js 271 0 [emitted] main
119-
chunk {0} output.js (main) 65 [rendered]
120-
> main [0] ./example.js
121-
[0] ./example.js 65 {0} [built] [1 warning]
122-
123-
WARNING in ./example.js
203+
Hash: 502a1d019f9df5485748bfc253e0ca08f68d64cf
204+
Version: webpack 1.4.3
205+
206+
WARNING in (de) ./example.js
124207
Missing localization: Missing Text
208+
Child en:
209+
Hash: 502a1d019f9df5485748
210+
Version: webpack 1.4.3
211+
Time: 104ms
212+
Asset Size Chunks Chunk Names
213+
en.output.js 272 0 [emitted] main
214+
chunk {0} en.output.js (main) 65 [rendered]
215+
> main [0] ./example.js
216+
[0] ./example.js 65 {0} [built]
217+
Child de:
218+
Hash: bfc253e0ca08f68d64cf
219+
Version: webpack 1.4.3
220+
Time: 96ms
221+
Asset Size Chunks Chunk Names
222+
de.output.js 271 0 [emitted] main
223+
chunk {0} de.output.js (main) 65 [rendered]
224+
> main [0] ./example.js
225+
[0] ./example.js 65 {0} [built] [1 warning]
226+
227+
WARNING in ./example.js
228+
Missing localization: Missing Text
125229
```

examples/i18n/build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
global.NO_TARGET_ARGS = true;
12
require("../build-common");

examples/i18n/template.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
This example uses the I18nPlugin in combination with the multi-compiler feature.
2+
3+
The `webpack.config.js` exports an array of all config combinations that should be compiled. In this example two different parameter for the I18nPlugin are used.
4+
5+
The I18nPlugin replaces every occurrence of the i18n function `__(...)` with a const string. i. e. `__("Hello World")` with `"Hello World"` resp. `"Hallo Welt"`.
6+
17

28
# example.js
39

@@ -11,19 +17,22 @@
1117
{{webpack.config.js}}
1218
```
1319

14-
> I recommend to use `new I18nPlugin(null)` for development
15-
> and write a small script that generates bundles for every language
16-
1720
# de.json
1821

1922
``` javascript
2023
{{de.json}}
2124
```
2225

23-
# js/output.js
26+
# js/de.output.js
27+
28+
``` javascript
29+
{{js/de.output.js}}
30+
```
31+
32+
# js/en.output.js
2433

2534
``` javascript
26-
{{js/output.js}}
35+
{{js/en.output.js}}
2736
```
2837

2938
# Info

examples/i18n/webpack.config.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1+
var path = require("path");
12
var I18nPlugin = require("i18n-webpack-plugin");
2-
module.exports = {
3-
plugins: [
4-
new I18nPlugin(
5-
require("./de.json") // or pass null to use defaults
6-
)
7-
]
8-
}
3+
var languages = {
4+
"en": null,
5+
"de": require("./de.json")
6+
};
7+
module.exports = Object.keys(languages).map(function(language) {
8+
return {
9+
name: language,
10+
entry: "./example",
11+
output: {
12+
path: path.join(__dirname, "js"),
13+
filename: language + ".output.js"
14+
},
15+
plugins: [
16+
new I18nPlugin(
17+
languages[language]
18+
)
19+
]
20+
};
21+
});

0 commit comments

Comments
 (0)