Browse Source

fix(nc-gui): use language alias when setting up state

pull/3819/head
braks 2 years ago
parent
commit
a2af66bae2
  1. 8
      packages/nc-gui/plugins/a.i18n.ts
  2. 6
      packages/nc-gui/plugins/state.ts

8
packages/nc-gui/plugins/a.i18n.ts

@ -2,6 +2,7 @@ import { defineNuxtPlugin } from 'nuxt/app'
import { createI18n } from 'vue-i18n'
import { nextTick } from 'vue'
import type { Language, NocoI18n } from '~/lib'
import { LanguageAlias } from '~/lib'
let globalI18n: NocoI18n
@ -26,7 +27,12 @@ export async function setI18nLanguage(locale: keyof typeof Language, i18n = glob
i18n.global.locale.value = locale
}
export async function loadLocaleMessages(locale: keyof typeof Language, i18n: NocoI18n = globalI18n) {
export async function loadLocaleMessages(
locale: keyof typeof Language | keyof typeof LanguageAlias,
i18n: NocoI18n = globalI18n,
) {
if (Object.keys(LanguageAlias).includes(locale)) locale = LanguageAlias[locale as keyof typeof LanguageAlias]
// load locale messages with dynamic import
const messages = await import(`../lang/${locale}.json`)

6
packages/nc-gui/plugins/state.ts

@ -1,5 +1,6 @@
import { defineNuxtPlugin, useApi, useGlobal } from '#imports'
import { loadLocaleMessages, setI18nLanguage } from '~/plugins/a.i18n'
import { Language, LanguageAlias } from '~/lib'
/**
* Initialize global state and watches for changes
@ -18,7 +19,10 @@ export default defineNuxtPlugin(async () => {
const { api } = useApi()
const currentLang = state.lang.value
let currentLang = state.lang.value
/** fall back to EN language if the current language cannot be found in Language or LanguagesAlias */
if (![...Object.keys(Language), ...Object.keys(LanguageAlias)].includes(currentLang)) state.lang.value = currentLang = 'en'
/** force load initial locale messages */
await loadLocaleMessages(currentLang)

Loading…
Cancel
Save