Skip to content

Commit

Permalink
fix(l10n): use localStorage in web environment
Browse files Browse the repository at this point in the history
  • Loading branch information
BroKun authored and lulusir committed Nov 15, 2024
1 parent e937296 commit 0365365
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
17 changes: 17 additions & 0 deletions .changeset/fast-rivers-grin.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 4 additions & 1 deletion packages/mana-l10n/src/l10n/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0365365

Please sign in to comment.