Renderer: Move vue-i18n to its own file

This commit is contained in:
Svallinn 2021-06-20 02:40:40 +01:00
parent 4f96aacbf6
commit 5cc954066b
No known key found for this signature in database
GPG Key ID: 09FB527F34037CCA
2 changed files with 32 additions and 29 deletions

View File

@ -0,0 +1,31 @@
import Vue from 'vue'
import VueI18n from 'vue-i18n'
import yaml from 'js-yaml'
import fs from 'fs'
const isDev = process.env.NODE_ENV === 'development'
Vue.use(VueI18n)
// List of locales approved for use
const activeLocales = ['en-US', 'en_GB', 'ar', 'bg', 'cs', 'da', 'de-DE', 'el', 'es', 'es-MX', 'et', 'fi', 'fr-FR', 'gl', 'he', 'hu', 'hr', 'id', 'is', 'it', 'ja', 'nb_NO', 'nl', 'nn', 'pl', 'pt', 'pt-BR', 'pt-PT', 'ru', 'sk', 'sl', 'sr', 'sv', 'tr', 'uk', 'vi', 'zh-CN', 'zh-TW']
const messages = {}
/* eslint-disable-next-line */
const fileLocation = isDev ? 'static/locales/' : `${__dirname}/static/locales/`
// Take active locales and load respective YAML file
activeLocales.forEach((locale) => {
try {
// File location when running in dev
const doc = yaml.load(fs.readFileSync(`${fileLocation}${locale}.yaml`))
messages[locale] = doc
} catch (e) {
console.log(e)
}
})
export default new VueI18n({
locale: 'en-US',
fallbackLocale: { default: 'en-US' },
messages: messages
})

View File

@ -3,6 +3,7 @@ import Vue from 'vue'
import App from './App.vue' import App from './App.vue'
import router from './router/index' import router from './router/index'
import store from './store/index' import store from './store/index'
import i18n from './i18n/index'
// import 'material-design-icons/iconfont/material-icons.css' // import 'material-design-icons/iconfont/material-icons.css'
import { library } from '@fortawesome/fontawesome-svg-core' import { library } from '@fortawesome/fontawesome-svg-core'
import { fas } from '@fortawesome/free-solid-svg-icons' import { fas } from '@fortawesome/free-solid-svg-icons'
@ -11,9 +12,6 @@ import { faBitcoin } from '@fortawesome/free-brands-svg-icons/faBitcoin'
import { faMonero } from '@fortawesome/free-brands-svg-icons/faMonero' import { faMonero } from '@fortawesome/free-brands-svg-icons/faMonero'
import { faMastodon } from '@fortawesome/free-brands-svg-icons/faMastodon' import { faMastodon } from '@fortawesome/free-brands-svg-icons/faMastodon'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import VueI18n from 'vue-i18n'
import yaml from 'js-yaml'
import fs from 'fs'
const isDev = process.env.NODE_ENV === 'development' const isDev = process.env.NODE_ENV === 'development'
@ -24,32 +22,6 @@ Vue.config.productionTip = isDev
library.add(fas, faGithub, faBitcoin, faMonero, faMastodon) library.add(fas, faGithub, faBitcoin, faMonero, faMastodon)
Vue.component('FontAwesomeIcon', FontAwesomeIcon) Vue.component('FontAwesomeIcon', FontAwesomeIcon)
Vue.use(VueI18n)
// List of locales approved for use
const activeLocales = ['en-US', 'en_GB', 'ar', 'bg', 'cs', 'da', 'de-DE', 'el', 'es', 'es-MX', 'et', 'fi', 'fr-FR', 'gl', 'he', 'hu', 'hr', 'id', 'is', 'it', 'ja', 'nb_NO', 'nl', 'nn', 'pl', 'pt', 'pt-BR', 'pt-PT', 'ru', 'sk', 'sl', 'sr', 'sv', 'tr', 'uk', 'vi', 'zh-CN', 'zh-TW']
const messages = {}
/* eslint-disable-next-line */
const fileLocation = isDev ? 'static/locales/' : `${__dirname}/static/locales/`
// Take active locales and load respective YAML file
activeLocales.forEach((locale) => {
try {
// File location when running in dev
const doc = yaml.load(fs.readFileSync(`${fileLocation}${locale}.yaml`))
messages[locale] = doc
} catch (e) {
console.log(e)
}
})
const i18n = new VueI18n({
locale: 'en-US', // set locale
fallbackLocale: {
default: 'en-US' // for the case systems locale has no corresponding .yaml file en-US gets set
},
messages // set locale messages
})
/* eslint-disable-next-line */ /* eslint-disable-next-line */
new Vue({ new Vue({