Skip to content

Commit 57ddbc0

Browse files
committed
added i18n example, fixed error/warning bug
1 parent c06fa37 commit 57ddbc0

File tree

10 files changed

+170
-2
lines changed

10 files changed

+170
-2
lines changed

examples/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ example demonstrating mixing CommonJs and AMD
4848

4949
example demonstrating creating WebWorkers with webpack and the worker-loader.
5050

51+
## i18n
52+
53+
example demonstrating localization.
54+
5155
# Requests
5256

5357
If you think a example is missing, please report it as issue. :)

examples/buildAll.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var cmds = [
1313
"cd require.resolve && node build.js",
1414
"cd mixed && node build.js",
1515
"cd web-worker && node build.js",
16+
"cd i18n && node build.js",
1617
];
1718

1819
var stack = function() {

examples/i18n/README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
```

examples/i18n/build.js

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

examples/i18n/de.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"Hello World": "Hallo Welt"
3+
}

examples/i18n/example.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
console.log(__("Hello World"));
2+
console.log(__("Missing Text"));

examples/i18n/template.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
# example.js
3+
4+
``` javascript
5+
{{example.js}}
6+
```
7+
8+
# webpack.config.js
9+
10+
``` javascript
11+
{{webpack.config.js}}
12+
```
13+
14+
> I recommend to use `new I18nPlugin(null)` for development
15+
> and write a small script that generates bundles for every language
16+
17+
# de.json
18+
19+
``` javascript
20+
{{de.json}}
21+
```
22+
23+
# js/output.js
24+
25+
``` javascript
26+
{{js/output.js}}
27+
```
28+
29+
# Info
30+
31+
## Uncompressed
32+
33+
```
34+
{{stdout}}
35+
```
36+
37+
## Minimized (uglify-js, no zip)
38+
39+
```
40+
{{min:stdout}}
41+
```

examples/i18n/webpack.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
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+
}

lib/Compilation.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ Compilation.prototype.getModule = function(module) {
7474
Compilation.prototype.buildModule = function(module, callback) {
7575
this.applyPlugins("build-module", module);
7676
module.build(this.options, this, this.resolvers.normal, this.inputFileSystem, function(err) {
77+
module.errors.forEach(function(err) {
78+
this.errors.push(err);
79+
}, this);
80+
module.warnings.forEach(function(err) {
81+
this.warnings.push(err);
82+
}, this);
7783
if(err) {
7884
this.applyPlugins("failed-module", module);
7985
return callback(err);

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack",
3-
"version": "0.9.0-beta24",
3+
"version": "0.9.0-beta25",
44
"author": "Tobias Koppers @sokra",
55
"description": "Packs CommonJs/AMD Modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jade, coffee, css, less, ... and your custom stuff.",
66
"dependencies": {
@@ -37,7 +37,8 @@
3737
"script-loader": "0.5.x",
3838
"bundle-loader": "0.5.x",
3939
"file-loader": "0.5.x",
40-
"val-loader": "0.5.x"
40+
"val-loader": "0.5.x",
41+
"i18n-webpack-plugin": "0.1.x"
4142
},
4243
"engines": {
4344
"node": ">=0.6"

0 commit comments

Comments
 (0)