From 55775f651f2be9043af805c414e6e6cc44eb1663 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Mon, 16 Oct 2023 07:45:53 +0800 Subject: [PATCH] Improve i18n support, close #2417 (#2418) --- assets/modules/i18n.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/assets/modules/i18n.ts b/assets/modules/i18n.ts index 2b16e9ccb548..f57f9d089277 100644 --- a/assets/modules/i18n.ts +++ b/assets/modules/i18n.ts @@ -7,9 +7,15 @@ const messages = Object.fromEntries( return [key.slice(14, yaml ? -5 : -4), value.default]; }), ); + +const userLang = navigator.language; +const shortLang = userLang.slice(0, 2); + +const locale = messages.hasOwnProperty(userLang) ? userLang : shortLang; + const i18n = createI18n({ legacy: false, - locale: navigator.language.slice(0, 2), + locale: locale, fallbackLocale: "en", messages, });