summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormokha <mokha@cisco.com>2018-09-29 14:35:51 -0600
committermokha <mokha@cisco.com>2018-09-29 14:35:51 -0600
commit34dbdff61d335d7300bb1b5d8482e2de51f09d43 (patch)
tree387675285dec1efdc54507dece4ae498ee3d2b00
parente4824d7ab69891db9c65e79ee6e2c3359d74bf7c (diff)
add i18n
* https://survivejs.com/webpack/techniques/i18n/
-rw-r--r--languages/fi.json1
-rw-r--r--package-lock.json6
-rw-r--r--package.json4
-rw-r--r--src/i18n.js1
-rw-r--r--webpack.i18n.js27
5 files changed, 38 insertions, 1 deletions
diff --git a/languages/fi.json b/languages/fi.json
new file mode 100644
index 0000000..0f5280f
--- /dev/null
+++ b/languages/fi.json
@@ -0,0 +1 @@
+{ "Hello world": "Terve maailma" }
diff --git a/package-lock.json b/package-lock.json
index c6c43a5..c4abd4e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -6140,6 +6140,12 @@
"integrity": "sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM=",
"dev": true
},
+ "i18n-webpack-plugin": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/i18n-webpack-plugin/-/i18n-webpack-plugin-1.0.0.tgz",
+ "integrity": "sha512-WMC2i05OuitjxYmeQU8XV4KJ+CrWnTOY5DwjygRz2dNByezfnTbVbV67qX4I53KHlscSnOsJyv6StuZxmm6J7w==",
+ "dev": true
+ },
"iconv-lite": {
"version": "0.4.23",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.23.tgz",
diff --git a/package.json b/package.json
index d7954db..070415e 100644
--- a/package.json
+++ b/package.json
@@ -4,9 +4,10 @@
"description": "",
"main": "index.js",
"scripts": {
+ "build": "webpack --env production",
+ "build:i18n": "webpack --config webpack.i18n.js",
"build:ssr": "webpack --config webpack.ssr.js",
"build:stats": "webpack --env production --json > stats.json",
- "build": "webpack --env production",
"start": "webpack-dev-server --env development",
"test": "echo \"Error: no test specified\" && exit 1"
},
@@ -31,6 +32,7 @@
"git-revision-webpack-plugin": "^3.0.3",
"glob": "^7.1.3",
"html-webpack-plugin": "^3.2.0",
+ "i18n-webpack-plugin": "^1.0.0",
"mini-css-extract-plugin": "^0.4.1",
"node-sass": "^4.9.3",
"optimize-css-assets-webpack-plugin": "^5.0.1",
diff --git a/src/i18n.js b/src/i18n.js
new file mode 100644
index 0000000..c108863
--- /dev/null
+++ b/src/i18n.js
@@ -0,0 +1 @@
+console.log(__("Hello world"));
diff --git a/webpack.i18n.js b/webpack.i18n.js
new file mode 100644
index 0000000..bc9ee39
--- /dev/null
+++ b/webpack.i18n.js
@@ -0,0 +1,27 @@
+const path = require("path");
+const glob = require("glob");
+const I18nPlugin = require("i18n-webpack-plugin");
+
+const PATHS = {
+ build: path.join(__dirname, "i18n-build"),
+ i18nDemo: path.join(__dirname, "src", "i18n.js"),
+};
+
+const TRANSLATIONS = [{ language: "en" }].concat(
+ glob.sync("./languages/*.json").map(file => ({
+ language: path.basename(file, path.extname(file)),
+ translation: require(file),
+ }))
+);
+
+module.exports = TRANSLATIONS.map(({ language, translation }) => ({
+ entry: {
+ index: PATHS.i18nDemo,
+ },
+ output: {
+ path: PATHS.build,
+ filename: `[name].${language}.js`,
+ },
+ plugins: [new I18nPlugin(translation)],
+}));
+