From 2195946f76832710c4fceb47c64e6c747cbed83d Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Thu, 29 Feb 2024 20:23:39 +0800 Subject: [PATCH] feat: use `Intl.getCanonicalLocales` check locale (#450) --- utils/getLanguage.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/utils/getLanguage.ts b/utils/getLanguage.ts index b0de77bd..6b853c3b 100644 --- a/utils/getLanguage.ts +++ b/utils/getLanguage.ts @@ -52,7 +52,13 @@ interface Language { */ function linkLocale(locale: string) { let linkedLocale: string - switch (locale) { + try { + // @ts-ignore + linkedLocale = Intl.getCanonicalLocales(locale)[0] + } catch (error) { + console.log(`${error.toString()}\n`) + } + switch (linkedLocale) { case 'zh-TW': case 'zh-HK': case 'zh-MO': -- 2.39.5