From 2ab921d6dbf3fbc93d14312b1aa27eee565d0a0f Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Wed, 14 Aug 2024 09:42:12 +0800 Subject: [PATCH] Load `en` by default, activate it later --- src/utils/lang.js | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/utils/lang.js b/src/utils/lang.js index ffb7ddd6..ae72af35 100644 --- a/src/utils/lang.js +++ b/src/utils/lang.js @@ -13,22 +13,12 @@ import localeMatch from '../utils/locale-match'; const { PHANPY_DEFAULT_LANG } = import.meta.env; export const DEFAULT_LANG = 'en'; -export const LOCALES = [DEFAULT_LANG]; +export const LOCALES = [DEFAULT_LANG, 'zh-CN']; if (import.meta.env.DEV) { LOCALES.push('pseudo-LOCALE'); } -export async function activateLang(lang) { - if (!lang || lang === DEFAULT_LANG) { - i18n.loadAndActivate({ locale: DEFAULT_LANG, messages }); - console.log('💬 ACTIVATE LANG', lang); - } else { - const { messages } = await import(`../locales/${lang}.po`); - i18n.loadAndActivate({ locale: lang, messages }); - console.log('💬 ACTIVATE LANG', lang); - } -} - +i18n.load(DEFAULT_LANG, messages); i18n.on('change', () => { const lang = i18n.locale; if (lang) { @@ -38,6 +28,17 @@ i18n.on('change', () => { } }); +export async function activateLang(lang) { + if (!lang || lang === DEFAULT_LANG) { + i18n.activate(DEFAULT_LANG); + console.log('💬 ACTIVATE LANG', DEFAULT_LANG, lang); + } else { + const { messages } = await import(`../locales/${lang}.po`); + i18n.loadAndActivate({ locale: lang, messages }); + console.log('💬 ACTIVATE LANG', lang, messages); + } +} + export function initActivateLang() { const lang = detect( fromUrl('lang'),