diff --git a/src/boot/i18n.ts b/src/boot/i18n.ts index cb86e78..ae96605 100644 --- a/src/boot/i18n.ts +++ b/src/boot/i18n.ts @@ -12,29 +12,19 @@ export const MessageLanguages = Object.keys(messages) as [MessageLanguage] export type MessageSchema = typeof messages['en'] /** - * Function to dynamically load Quasar language packs, see + * Defines how to load a quasar language pack. Wrapped in function calls to not resolve the promise early * https://quasar.dev/options/quasar-language-packs */ -async function loadLangPack (lang: MessageLanguage, fileName: string = lang): Promise { - try { - return (await import(`../../node_modules/quasar/lang/${fileName}.mjs`)).default - } catch (err) { - console.error(`Failed to load Quasar language pack for locale "${lang}": ${errorToString(err)}`) - throw err - } -} - -// TODO: Lazy-load language packs; 'await' is blocking in this context -const quasarLangPacks: { [k in MessageLanguage]: QuasarLanguage} = { - de: await loadLangPack('de'), - en: await loadLangPack('en', 'en-US'), - es: await loadLangPack('es'), - fr: await loadLangPack('fr'), - it: await loadLangPack('it'), - nl: await loadLangPack('nl'), - pl: await loadLangPack('pl'), - pt: await loadLangPack('pt'), - sv: await loadLangPack('sv') +const quasarLangPacks: { [k in MessageLanguage]: () => Promise} = { + de: async () => (await import('quasar/lang/de')).default, + en: async () => (await import('quasar/lang/en-US')).default, + es: async () => (await import('quasar/lang/es')).default, + fr: async () => (await import('quasar/lang/fr')).default, + it: async () => (await import('quasar/lang/it')).default, + nl: async () => (await import('quasar/lang/nl')).default, + pl: async () => (await import('quasar/lang/pl')).default, + pt: async () => (await import('quasar/lang/pt')).default, + sv: async () => (await import('quasar/lang/sv')).default } // See https://vue-i18n.intlify.dev/guide/advanced/typescript.html#global-resource-schema-type-definition @@ -119,5 +109,8 @@ export default boot(({ app }) => { export function setGlobalLocale (lang: MessageLanguage) { i18n.global.locale.value = lang - Quasar.lang.set(quasarLangPacks[lang]) + // This is cached by vite. Its transpiled into a simple import statement, which if called a second time won't make another request to the server + quasarLangPacks[lang]() + .then(pack => Quasar.lang.set(pack)) + .catch(err => console.error(`Failed to load Quasar language pack for locale "${lang}": ${errorToString(err)}`)) } diff --git a/src/boot/openlayers.ts b/src/boot/openlayers.ts index 0592f0d..e8f0b57 100644 --- a/src/boot/openlayers.ts +++ b/src/boot/openlayers.ts @@ -3,5 +3,6 @@ import OpenLayersMap from 'vue3-openlayers' import 'vue3-openlayers/dist/vue3-openlayers.css' export default boot(({ app }) => { + // TODO: Make this optional; Only used on MapComponent. app.use(OpenLayersMap) }) diff --git a/src/misc.ts b/src/misc.ts index dce8bf5..424390f 100644 --- a/src/misc.ts +++ b/src/misc.ts @@ -16,7 +16,7 @@ export function errorToString (e: unknown, log = false): string { } else { console.warn('Unknown error:', e) // Debug this type of error and decide how to handle it - if (process.env.DEV) debugger + if (process.env.DEV) debugger // eslint-disable-line no-debugger return 'unknown error type' } }