diff --git a/frontend/src/i18n.js b/frontend/src/i18n.js new file mode 100644 index 0000000..fd7eb1b --- /dev/null +++ b/frontend/src/i18n.js @@ -0,0 +1,42 @@ +import Vue from 'vue' +import VueI18n from 'vue-i18n' + +import zh from '@/lang/zh' + +let loadedLocales = ['zh'] + +Vue.use(VueI18n) + +export async function setLocale(locale) { + if (loadedLocales.indexOf(locale) === -1) { + // eslint-disable-next-line prefer-template + let langModule = await import('@/lang/' + locale) + i18n.setLocaleMessage(locale, langModule.default) + loadedLocales.push(locale) + } + window.localStorage.lang = i18n.locale = locale +} + +export const i18n = new VueI18n({ + locale: 'zh', + fallbackLocale: 'zh', + messages: { + zh + } +}) + +function getDefaultLocale() { + let locale = window.localStorage.lang + if (!locale) { + let lang = navigator.language + if (lang.startsWith('zh')) { + locale = 'zh' + } else if (lang.startsWith('ja')) { + locale = 'ja' + } else { + locale = 'en' + } + } + return locale +} +setLocale(getDefaultLocale()) diff --git a/frontend/src/layout/Sidebar.vue b/frontend/src/layout/Sidebar.vue index 67fb491..e03cd6f 100644 --- a/frontend/src/layout/Sidebar.vue +++ b/frontend/src/layout/Sidebar.vue @@ -30,24 +30,31 @@ - {{ name }} + + +