1 | # i18n loader for webpack
|
2 |
|
3 | ## Usage
|
4 |
|
5 | ### ./colors.json
|
6 |
|
7 | ``` javascript
|
8 | {
|
9 | "red": "red",
|
10 | "green": "green",
|
11 | "blue": "blue"
|
12 | }
|
13 | ```
|
14 |
|
15 | ### ./de-de.colors.json
|
16 |
|
17 | ``` javascript
|
18 | {
|
19 | "red": "rot",
|
20 | "green": "gr�n"
|
21 | }
|
22 | ```
|
23 |
|
24 | ### call it
|
25 |
|
26 | ``` javascript
|
27 | // assuming our locale is "de-de-berlin"
|
28 | var locale = require("i18n!./colors.json");
|
29 |
|
30 | // wait for ready, this is only required once for all locales in a web app
|
31 | // because all locales of the same language are merged into one chuck
|
32 | locale(function() {
|
33 | console.log(locale.red); // prints rot
|
34 | console.log(locale.blue); // prints blue
|
35 | });
|
36 | ```
|
37 |
|
38 | ### options
|
39 |
|
40 | You should tell the loader about all your locales, if you want to load them once
|
41 | and than want to use them synchronous.
|
42 |
|
43 | ``` javascript
|
44 | {
|
45 | "i18n": {
|
46 | "locales": [
|
47 | "de",
|
48 | "de-de",
|
49 | "fr"
|
50 | ],
|
51 | // "bundleTogether": false
|
52 | // this can disable the bundling of locales
|
53 | }
|
54 | }
|
55 | ```
|
56 |
|
57 | ### alternative calls
|
58 |
|
59 | ``` javascript
|
60 | require("i18n/choose!./file.js"); // chooses the correct file by locale,
|
61 | // but it do not merge the objects
|
62 | require("i18n/concat!./file.js"); // concatinate all fitting locales
|
63 | require("i18n/merge!./file.js"); // merges the resulting objects
|
64 | // ./file.js is excuted while compiling
|
65 | require("i18n!./file.json") == require("i18n/merge!json!./file.json")
|
66 | ```
|
67 |
|
68 | Don't forget to polyfill `require` if you want to use it in node.
|
69 | See `webpack` documentation.
|
70 |
|
71 | ## License
|
72 |
|
73 | MIT (http://www.opensource.org/licenses/mit-license.php) |
\ | No newline at end of file |