From 03653659a7400430493903e33f44dc2f048576df 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 --- .changeset/fast-rivers-grin.md | 17 +++++++++++++++++ packages/mana-l10n/src/l10n/index.ts | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 .changeset/fast-rivers-grin.md diff --git a/.changeset/fast-rivers-grin.md b/.changeset/fast-rivers-grin.md new file mode 100644 index 0000000..edf9ed7 --- /dev/null +++ b/.changeset/fast-rivers-grin.md @@ -0,0 +1,17 @@ +--- +'@difizen/babel-preset-mana': patch +'@difizen/mana-observable': patch +'@difizen/umi-plugin-mana': patch +'@difizen/mana-syringe': patch +'@difizen/mana-common': patch +'@difizen/mana-react': patch +'@difizen/mana-react-example': patch +'@difizen/mana-core': patch +'@difizen/mana-l10n': patch +'@difizen/mana-app': patch +'@difizen/mana-umi-example': patch +'@difizen/mana-ui': patch +'@difizen/mana-docs': patch +--- + +fix: localStorage is not defined. 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;