Skip to content

Commit

Permalink
fix: i18n issue
Browse files Browse the repository at this point in the history
  • Loading branch information
zggmd committed Mar 25, 2024
1 parent f4945ea commit 8a7afe2
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 149 deletions.
4 changes: 2 additions & 2 deletions packages/chat/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@yuntijs/chat",
"version": "0.1.0-beta.9",
"version": "0.1.0-beta.10",
"description": "对话组件",
"keywords": [],
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -28,7 +28,7 @@
"peerDependencies": {
"@ant-design/icons": "^5.0.0",
"@lobehub/ui": "^1.128.4",
"@yuntijs/arcadia-bff-sdk": "^1.1.6",
"@yuntijs/arcadia-bff-sdk": "^1.2.3",
"antd": "^5.0.0",
"lodash": "^4.17.21",
"lucide-react": "^0.300.0",
Expand Down
16 changes: 15 additions & 1 deletion packages/chat/src/utils/kiwiI18N.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,27 @@ export enum LangEnum {
'zh' = 'zh-CN',
}

// 解析cookie
const parseCookies = () => {
const cookies: { [key: string]: string } = {};
document.cookie &&
document.cookie.split(';').forEach(cookie => {
const [name, value] = cookie.trim().split('=');
cookies[name] = value;
});
return cookies;
};

const LOCALE_KEY = 'intl_locale';
const _locale =
window.localStorage.getItem(LOCALE_KEY) ||
(typeof navigator === 'object' && typeof navigator.language === 'string'
? navigator.language
: 'zh-CN');
const locale = _locale.startsWith('en') ? 'en-US' : 'zh-CN';
const locale =
_locale.startsWith('en') || parseCookies()?.['NEXT_LOCALE']?.toLocaleLowerCase() === 'en'
? 'en-US'
: 'zh-CN';

const getLocale = () => locale;

Expand Down
Loading

0 comments on commit 8a7afe2

Please sign in to comment.