refs #901 Load translation json directly instead of i18next-sync-fs-backend

This commit is contained in:
AkiraFukushima 2019-11-27 00:29:02 +09:00
parent 094c19a2d1
commit d8e84b18f8
5 changed files with 78 additions and 50 deletions

View File

@ -13,9 +13,7 @@ let mainConfig = {
entry: { entry: {
main: path.join(__dirname, '../src/main/index.ts') main: path.join(__dirname, '../src/main/index.ts')
}, },
externals: [ externals: [...Object.keys(dependencies || {})],
...Object.keys(dependencies || {})
],
module: { module: {
rules: [ rules: [
{ {
@ -42,6 +40,12 @@ let mainConfig = {
{ {
test: /\.node$/, test: /\.node$/,
use: 'node-loader' use: 'node-loader'
},
{
test: /\.json$/,
exclude: /node_modules/,
use: 'json-loader',
type: 'javascript/auto'
} }
] ]
}, },
@ -81,7 +85,7 @@ let mainConfig = {
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
mainConfig.plugins.push( mainConfig.plugins.push(
new webpack.DefinePlugin({ new webpack.DefinePlugin({
'__static': `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"` __static: `"${path.join(__dirname, '../static').replace(/\\/g, '\\\\')}"`
}) })
) )
} }

View File

@ -117,6 +117,12 @@ let rendererConfig = {
name: 'fonts/[name]--[folder].[ext]' name: 'fonts/[name]--[folder].[ext]'
} }
} }
},
{
test: /\.json$/,
exclude: /node_modules/,
use: 'json-loader',
type: 'javascript/auto'
} }
] ]
}, },

42
package-lock.json generated
View File

@ -6395,7 +6395,7 @@
"dependencies": { "dependencies": {
"resolve": { "resolve": {
"version": "1.1.7", "version": "1.1.7",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz", "resolved": "http://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz",
"integrity": "sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs=", "integrity": "sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs=",
"dev": true "dev": true
} }
@ -13049,36 +13049,6 @@
"resolved": "https://registry.npmjs.org/i18next/-/i18next-12.1.0.tgz", "resolved": "https://registry.npmjs.org/i18next/-/i18next-12.1.0.tgz",
"integrity": "sha512-AexmwGkKxwKfo5fGeXTWEY4xqzRPigQ1S/0InOUUVziGO54cd4fKyYK8ED1Thx9fd+WA3fRSZ+1iekvFQMbsFw==" "integrity": "sha512-AexmwGkKxwKfo5fGeXTWEY4xqzRPigQ1S/0InOUUVziGO54cd4fKyYK8ED1Thx9fd+WA3fRSZ+1iekvFQMbsFw=="
}, },
"i18next-sync-fs-backend": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/i18next-sync-fs-backend/-/i18next-sync-fs-backend-1.1.1.tgz",
"integrity": "sha512-IoJCGid/NLqPFp+2qsumwOy1hG6jENKSIW9BozHL/3ZsjunH0P7iZLRMADljIuFntKlA63suPIPJWGR2SkxLIg==",
"requires": {
"js-yaml": "3.13.1",
"json5": "0.5.0"
},
"dependencies": {
"esprima": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A=="
},
"js-yaml": {
"version": "3.13.1",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz",
"integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==",
"requires": {
"argparse": "^1.0.7",
"esprima": "^4.0.0"
}
},
"json5": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/json5/-/json5-0.5.0.tgz",
"integrity": "sha1-myBxWwJsvjd4/Xae3M2CLYMypbI="
}
}
},
"iconv-lite": { "iconv-lite": {
"version": "0.4.24", "version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
@ -15618,6 +15588,12 @@
"integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg=", "integrity": "sha1-Wx85evx11ne96Lz8Dkfh+aPZqJg=",
"dev": true "dev": true
}, },
"json-loader": {
"version": "0.5.7",
"resolved": "https://registry.npmjs.org/json-loader/-/json-loader-0.5.7.tgz",
"integrity": "sha512-QLPs8Dj7lnf3e3QYS1zkCo+4ZwqOiF9d/nZnYozTISxXWCfNs9yuky5rJw4/W34s7POaNlbZmQGaB5NiXCbP4w==",
"dev": true
},
"json-parse-better-errors": { "json-parse-better-errors": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz",
@ -16524,7 +16500,7 @@
}, },
"readable-stream": { "readable-stream": {
"version": "2.3.6", "version": "2.3.6",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
"integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==",
"dev": true, "dev": true,
"requires": { "requires": {
@ -16539,7 +16515,7 @@
}, },
"string_decoder": { "string_decoder": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
"dev": true, "dev": true,
"requires": { "requires": {

View File

@ -183,7 +183,6 @@
"hawk": "^7.0.10", "hawk": "^7.0.10",
"hoek": "^6.1.3", "hoek": "^6.1.3",
"i18next": "^12.1.0", "i18next": "^12.1.0",
"i18next-sync-fs-backend": "^1.1.1",
"lodash": "^4.17.15", "lodash": "^4.17.15",
"megalodon": "2.0.1", "megalodon": "2.0.1",
"moment": "^2.21.0", "moment": "^2.21.0",
@ -266,6 +265,7 @@
"html-webpack-plugin": "^3.2.0", "html-webpack-plugin": "^3.2.0",
"jest": "^24.5.0", "jest": "^24.5.0",
"jsdom": "^15.2.1", "jsdom": "^15.2.1",
"json-loader": "^0.5.7",
"listr": "^0.14.3", "listr": "^0.14.3",
"mini-css-extract-plugin": "^0.4.5", "mini-css-extract-plugin": "^0.4.5",
"node-loader": "^0.6.0", "node-loader": "^0.6.0",

View File

@ -1,24 +1,66 @@
import * as path from 'path'
import i18next, { InitOptions } from 'i18next' import i18next, { InitOptions } from 'i18next'
import Backend from 'i18next-sync-fs-backend' import cs from '~/src/config/locales/cs/translation.json'
import de from '~/src/config/locales/de/translation.json'
import en from '~/src/config/locales/en/translation.json'
import es_es from '~/src/config/locales/es_es/translation.json'
import fr from '~/src/config/locales/fr/translation.json'
import ja from '~/src/config/locales/it/translation.json'
import ko from '~/src/config/locales/ko/translation.json'
import no from '~/src/config/locales/no/translation.json'
import pl from '~/src/config/locales/pl/translation.json'
import pt_pt from '~/src/config/locales/pt_pt/translation.json'
import ru from '~/src/config/locales/ru/translation.json'
import sv_se from '~/src/config/locales/sv_se/translation.json'
import zh_cn from '~/src/config/locales/zh_cn/translation.json'
const options: InitOptions = { const options: InitOptions = {
initImmediate: false, initImmediate: false,
lng: 'en', lng: 'en',
fallbackLng: 'en', fallbackLng: 'en',
saveMissing: true, saveMissing: true,
backend: { resources: {
// path where resources get loaded from cs: {
loadPath: path.resolve(__dirname, './locales/{{lng}}/{{ns}}.json'), translation: cs
},
// path to post missing resources de: {
addPath: path.resolve(__dirname, './locales/en/{{ns}}.json'), translation: de
},
// jsonIndent to use when storing json files en: {
jsonIndent: 2 translation: en
},
es_es: {
translation: es_es
},
fr: {
translation: fr
},
ja: {
translation: ja
},
ko: {
translation: ko
},
no: {
translation: no
},
pl: {
translation: pl
},
pt_pt: {
translation: pt_pt
},
ru: {
translation: ru
},
sv_se: {
translation: sv_se
},
zh_cn: {
translation: zh_cn
}
} }
} }
i18next.use(Backend).init(options) i18next.init(options)
export default i18next export default i18next