Extract language list to its own file

This commit is contained in:
Tusooa Zhu 2022-09-20 19:27:26 -04:00
parent 0445d7c882
commit d5411c9f88
No known key found for this signature in database
GPG Key ID: 7B467EDE43A08224
4 changed files with 64 additions and 35 deletions

View File

@ -23,6 +23,7 @@
"@fortawesome/free-solid-svg-icons": "6.2.0",
"@fortawesome/vue-fontawesome": "3.0.1",
"@kazvmoe-infra/pinch-zoom-element": "1.2.0",
"@kazvmoe-infra/unicode-emoji-json": "^0.4.0",
"@ruffle-rs/ruffle": "0.1.0-nightly.2022.7.12",
"@vuelidate/core": "2.0.0-alpha.44",
"@vuelidate/validators": "2.0.0-alpha.31",
@ -34,8 +35,8 @@
"escape-html": "1.0.3",
"js-cookie": "3.0.1",
"localforage": "1.10.0",
"parse-link-header": "2.0.0",
"lozad": "^1.16.0",
"parse-link-header": "2.0.0",
"phoenix": "1.6.2",
"punycode.js": "2.1.0",
"qrcode": "1.5.0",
@ -116,8 +117,8 @@
"stylelint": "13.13.1",
"stylelint-config-standard": "20.0.0",
"stylelint-rscss": "0.4.0",
"vue-loader": "17.0.0",
"unicode-emoji-json": "^0.3.0",
"vue-loader": "17.0.0",
"vue-style-loader": "4.1.3",
"webpack": "5.74.0",
"webpack-dev-middleware": "3.7.3",

44
src/i18n/languages.js Normal file
View File

@ -0,0 +1,44 @@
const languages = [
'ar',
'ca',
'cs',
'de',
'eo',
'en',
'es',
'et',
'eu',
'fi',
'fr',
'ga',
'he',
'hu',
'it',
'ja',
'ja_easy',
'ko',
'nb',
'nl',
'oc',
'pl',
'pt',
'ro',
'ru',
'sk',
'te',
'uk',
'zh',
'zh_Hant'
]
const specialJsonName = {
ja: 'ja_pedantic'
}
const langCodeToJsonName = (code) => specialJsonName[code] || code
module.exports = {
languages,
langCodeToJsonName
}

View File

@ -7,46 +7,25 @@
// sed -i -e "s/'//gm" -e 's/"/\\"/gm' -re 's/^( +)(.+?): ((.+?))?(,?)(\{?)$/\1"\2": "\4"/gm' -e 's/\"\{\"/{/g' -e 's/,"$/",/g' file.json
// There's only problem that apostrophe character ' gets replaced by \\ so you have to fix it manually, sorry.
const loaders = {
ar: () => import('./ar.json'),
ca: () => import('./ca.json'),
cs: () => import('./cs.json'),
de: () => import('./de.json'),
eo: () => import('./eo.json'),
es: () => import('./es.json'),
et: () => import('./et.json'),
eu: () => import('./eu.json'),
fi: () => import('./fi.json'),
fr: () => import('./fr.json'),
ga: () => import('./ga.json'),
he: () => import('./he.json'),
hu: () => import('./hu.json'),
it: () => import('./it.json'),
ja: () => import('./ja_pedantic.json'),
ja_easy: () => import('./ja_easy.json'),
ko: () => import('./ko.json'),
nb: () => import('./nb.json'),
nl: () => import('./nl.json'),
oc: () => import('./oc.json'),
pl: () => import('./pl.json'),
pt: () => import('./pt.json'),
ro: () => import('./ro.json'),
ru: () => import('./ru.json'),
sk: () => import('./sk.json'),
te: () => import('./te.json'),
uk: () => import('./uk.json'),
zh: () => import('./zh.json'),
zh_Hant: () => import('./zh_Hant.json')
import { languages, langCodeToJsonName } from './languages.js'
const hasLanguageFile = (code) => languages.includes(code)
const loadLanguageFile = (code) => {
return import(
/* webpackInclude: /\.json$/ */
`./${langCodeToJsonName(code)}.json`
)
}
const messages = {
languages: ['en', ...Object.keys(loaders)],
languages,
default: {
en: require('./en.json').default
},
setLanguage: async (i18n, language) => {
if (loaders[language]) {
const messages = await loaders[language]()
if (hasLanguageFile(language)) {
const messages = await loadLanguageFile(language)
i18n.setLocaleMessage(language, messages.default)
}
i18n.locale = language

View File

@ -1629,6 +1629,11 @@
dependencies:
pointer-tracker "^2.0.3"
"@kazvmoe-infra/unicode-emoji-json@^0.4.0":
version "0.4.0"
resolved "https://registry.yarnpkg.com/@kazvmoe-infra/unicode-emoji-json/-/unicode-emoji-json-0.4.0.tgz#555bab2f8d11db74820ef0a2fbe2805b17c22587"
integrity sha512-22OffREdHzD0U6A/W4RaFPV8NR73za6euibtAxNxO/fu5A6TwxRO2lAdbDWKJH9COv/vYs8zqfEiSalXH2nXJA==
"@nightwatch/chai@5.0.2":
version "5.0.2"
resolved "https://registry.yarnpkg.com/@nightwatch/chai/-/chai-5.0.2.tgz#86b20908fc090dffd5c9567c0392bc6a494cc2e6"