webpack-easyi18n 0.3.5 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/index.js +11 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webpack-easyi18n",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8",
|
|
4
4
|
"description": "Go from gettext catalog (.po files) to embeded localization in your Webpack bundles",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=4.3.0 <5.0.0 || >=5.10"
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"main": "src/index.js",
|
|
12
12
|
"scripts": {
|
|
13
13
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
14
|
-
"clean:example": "rimraf example\\dist",
|
|
14
|
+
"clean:example": "rimraf example\\dist example\\locale\\webpack-easyi18n-temp",
|
|
15
15
|
"build:example": "npm run clean:example && webpack -c example\\webpack.config.js"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
package/src/index.js
CHANGED
|
@@ -15,6 +15,12 @@ class EasyI18nPlugin {
|
|
|
15
15
|
includeUrls: null,
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
static escapeSpeechMarks = (string) => {
|
|
19
|
+
return string
|
|
20
|
+
.replace(/'/g, '\\\'')
|
|
21
|
+
.replace(/"/g, '\\"');
|
|
22
|
+
}
|
|
23
|
+
|
|
18
24
|
constructor(locale, options = {}) {
|
|
19
25
|
this.locale = locale;
|
|
20
26
|
this.options = {
|
|
@@ -24,12 +30,6 @@ class EasyI18nPlugin {
|
|
|
24
30
|
}
|
|
25
31
|
|
|
26
32
|
apply(compiler) {
|
|
27
|
-
const save = (target) => {
|
|
28
|
-
return result => {
|
|
29
|
-
writeFileSync(target, result);
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
33
|
const mkdir = (dirPath) => {
|
|
34
34
|
try {
|
|
35
35
|
mkdirSync(dirPath);
|
|
@@ -38,8 +38,8 @@ class EasyI18nPlugin {
|
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
compiler.hooks.
|
|
42
|
-
compilation.hooks.processAssets.
|
|
41
|
+
compiler.hooks.thisCompilation.tap('EasyI18nPlugin', (compilation) => {
|
|
42
|
+
compilation.hooks.processAssets.tapPromise(
|
|
43
43
|
{
|
|
44
44
|
name: 'EasyI18nPlugin',
|
|
45
45
|
state: compilation.PROCESS_ASSETS_STAGE_DERIVED,
|
|
@@ -54,9 +54,9 @@ class EasyI18nPlugin {
|
|
|
54
54
|
mkdir(path.resolve(path.join(this.options.localesPath, "/webpack-easyi18n-temp/")));
|
|
55
55
|
|
|
56
56
|
console.log(`Reading translations from ${poPath}`)
|
|
57
|
-
await gettextToI18Next(localeKey, readFileSync(poPath), {});
|
|
57
|
+
var lookupData = await gettextToI18Next(localeKey, readFileSync(poPath), {});
|
|
58
58
|
var translationLookupPath = path.join(this.options.localesPath, `/webpack-easyi18n-temp/${localeKey}.json`);
|
|
59
|
-
|
|
59
|
+
writeFileSync(translationLookupPath, lookupData);
|
|
60
60
|
console.log(`${localeKey} translation lookup file created ${translationLookupPath}`);
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -133,7 +133,7 @@ class EasyI18nPlugin {
|
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
-
return replacement;
|
|
136
|
+
return EasyI18nPlugin.escapeSpeechMarks(replacement);
|
|
137
137
|
});
|
|
138
138
|
|
|
139
139
|
compilation.updateAsset(filename, new SourceMapSource(
|