From e14902ffaae21b63bef71c2d59a6cf3d2f6614b7 Mon Sep 17 00:00:00 2001 From: brokun Date: Fri, 15 Nov 2024 10:56:30 +0800 Subject: [PATCH] fix(l10n): use localStorage in web environment --- packages/mana-l10n/src/l10n/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/mana-l10n/src/l10n/index.ts b/packages/mana-l10n/src/l10n/index.ts index de681db..bc578f8 100644 --- a/packages/mana-l10n/src/l10n/index.ts +++ b/packages/mana-l10n/src/l10n/index.ts @@ -36,7 +36,10 @@ export enum L10nLang { } function getDefaultlang() { - const localeValue = localStorage?.getItem('locale') || locale; + let localeValue = locale; + if (typeof navigator === 'object') { + localeValue = localStorage?.getItem('locale') || locale; + } const localeStr = localeValue.toLowerCase(); if (localeStr === 'zh' || localeStr.startsWith('zh-')) { return L10nLang.zhCN;