From 888336cbec7688ed60456e988c1bf8789ce7c8f3 Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Tue, 13 Feb 2018 17:45:27 -0500 Subject: [PATCH] Adding loader for i18next translation files --- package.json | 5 ++--- src/i18n.js | 1 + src/locales/index.js | 6 +----- webpack.common.js | 18 +++++++----------- yarn.lock | 36 ++++++++++++++++++++++++++++-------- 5 files changed, 39 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 2c20591..c409b8e 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ ] }, "dependencies": { + "@alienfast/i18next-loader": "^1.0.14", "babel-core": "^6.26.0", "babel-eslint": "^8.2.1", "babel-jest": "^22.2.2", @@ -73,7 +74,6 @@ "i18next-browser-languagedetector": "^2.1.0", "identity-obj-proxy": "^3.0.0", "jest": "^22.2.2", - "json-loader": "^0.5.7", "npm-run-all": "^4.1.2", "postcss-cssnext": "^3.1.0", "postcss-import": "^11.1.0", @@ -89,8 +89,7 @@ "webpack": "^3.10.0", "webpack-merge": "^4.1.1", "webpack-node-externals": "^1.6.0", - "workbox-webpack-plugin": "^2.1.2", - "yaml-loader": "^0.5.0" + "workbox-webpack-plugin": "^2.1.2" }, "devDependencies": { "http-server": "^0.11.1", diff --git a/src/i18n.js b/src/i18n.js index ff8c835..981c4cd 100644 --- a/src/i18n.js +++ b/src/i18n.js @@ -9,6 +9,7 @@ i18n .use(LangDetector) .init({ fallbackLng: 'en', + fallbackNS: 'missing', debug: (process.env.NODE_ENV !== 'production'), resources: locales }); diff --git a/src/locales/index.js b/src/locales/index.js index 80aa256..9305273 100644 --- a/src/locales/index.js +++ b/src/locales/index.js @@ -1,5 +1 @@ -export default { - en: { - translation: require('./en/translation.yaml') - } -}; +// Here so webpack has something to resolve diff --git a/webpack.common.js b/webpack.common.js index b6f8074..2250f22 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -85,6 +85,13 @@ module.exports = { ], module: { rules: [ + { + test: /locales/, + loader: '@alienfast/i18next-loader', + options: { + basenameAsNamespace: true + } + }, { test: /\.js$/, exclude: /node_modules/, @@ -143,17 +150,6 @@ module.exports = { { test: /\.svg$/, loader: 'svg-react-loader' - }, - { - test: /\.yaml$/, - use: [ - { - loader: 'json-loader' - }, - { - loader: 'yaml-loader' - } - ] } ] } diff --git a/yarn.lock b/yarn.lock index 804eb85..66c7d36 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,15 @@ # yarn lockfile v1 +"@alienfast/i18next-loader@^1.0.14": + version "1.0.14" + resolved "https://registry.yarnpkg.com/@alienfast/i18next-loader/-/i18next-loader-1.0.14.tgz#768543058ae709d0630cb1c82b06af0c9e76dfa4" + dependencies: + glob-all "^3.1.0" + js-yaml "^3.10.0" + loader-utils "^1.1.0" + lodash "^4.17.4" + "@babel/code-frame@7.0.0-beta.36": version "7.0.0-beta.36" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.0.0-beta.36.tgz#2349d7ec04b3a06945ae173280ef8579b63728e4" @@ -3244,6 +3253,13 @@ getpass@^0.1.1: dependencies: assert-plus "^1.0.0" +glob-all@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/glob-all/-/glob-all-3.1.0.tgz#8913ddfb5ee1ac7812656241b03d5217c64b02ab" + dependencies: + glob "^7.0.5" + yargs "~1.2.6" + glob-base@^0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/glob-base/-/glob-base-0.3.0.tgz#dbb164f6221b1c0b1ccf82aea328b497df0ea3c4" @@ -4465,7 +4481,7 @@ js-tokens@^3.0.0, js-tokens@^3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" -js-yaml@^3.4.3, js-yaml@^3.5.2, js-yaml@^3.7.0, js-yaml@^3.9.1: +js-yaml@^3.10.0, js-yaml@^3.4.3, js-yaml@^3.7.0, js-yaml@^3.9.1: version "3.10.0" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.10.0.tgz#2e78441646bd4682e963f22b6e92823c309c62dc" dependencies: @@ -4522,7 +4538,7 @@ jsesc@~0.5.0: version "0.5.0" resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d" -json-loader@^0.5.4, json-loader@^0.5.7: +json-loader@^0.5.4: version "0.5.7" resolved "https://registry.yarnpkg.com/json-loader/-/json-loader-0.5.7.tgz#dca14a70235ff82f0ac9a3abeb60d337a365185d" @@ -5018,6 +5034,10 @@ minimist@0.0.8: version "0.0.8" resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" +minimist@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.1.0.tgz#99df657a52574c21c9057497df742790b2b4c0de" + minimist@^1.1.0, minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2.0: version "1.2.0" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" @@ -8480,12 +8500,6 @@ yallist@^2.1.2: version "2.1.2" resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52" -yaml-loader@^0.5.0: - version "0.5.0" - resolved "https://registry.yarnpkg.com/yaml-loader/-/yaml-loader-0.5.0.tgz#86b1982d84a8e429e6647d93de9a0169e1c15827" - dependencies: - js-yaml "^3.5.2" - yargs-parser@^4.2.0: version "4.2.1" resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-4.2.1.tgz#29cceac0dc4f03c6c87b4a9f217dd18c9f74871c" @@ -8569,6 +8583,12 @@ yargs@^8.0.2: y18n "^3.2.1" yargs-parser "^7.0.0" +yargs@~1.2.6: + version "1.2.6" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-1.2.6.tgz#9c7b4a82fd5d595b2bf17ab6dcc43135432fe34b" + dependencies: + minimist "^0.1.0" + yargs@~3.10.0: version "3.10.0" resolved "https://registry.yarnpkg.com/yargs/-/yargs-3.10.0.tgz#f7ee7bd857dd7c1d2d38c0e74efbd681d1431fd1"