docs: add comments to the src/routes & src/store & src/utils directory
This commit is contained in:
@@ -1,11 +1,22 @@
|
||||
/*
|
||||
* @Description:
|
||||
* @Version: 0.0.1
|
||||
* @Author: yujiangping
|
||||
* @Date: 2026-01-05 17:22:23
|
||||
* @LastEditors: yujiangping
|
||||
* @LastEditTime: 2026-01-15 21:02:43
|
||||
* @Author: ZhaoYing
|
||||
* @Date: 2026-02-02 16:33:22
|
||||
* @Last Modified by: ZhaoYing
|
||||
* @Last Modified time: 2026-02-02 16:33:22
|
||||
*/
|
||||
/**
|
||||
* Locale Store
|
||||
*
|
||||
* Manages internationalization (i18n) and localization with:
|
||||
* - Language switching (English/Chinese)
|
||||
* - Timezone management
|
||||
* - Ant Design locale configuration
|
||||
* - Custom Tour component translations
|
||||
* - Day.js timezone support
|
||||
*
|
||||
* @store
|
||||
*/
|
||||
|
||||
import { create } from 'zustand'
|
||||
import enUS from 'antd/locale/en_US';
|
||||
import zhCN from 'antd/locale/zh_CN';
|
||||
@@ -14,13 +25,12 @@ import dayjs from 'dayjs'
|
||||
import timezone from 'dayjs/plugin/timezone';
|
||||
import utc from 'dayjs/plugin/utc';
|
||||
import i18n from '@/i18n';
|
||||
import { timezoneToAntdLocaleMap } from '@/utils/timezones';
|
||||
|
||||
// 扩展dayjs插件
|
||||
/** Extend dayjs with timezone plugins */
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
|
||||
// 自定义中文 locale,修改 Tour 组件的按钮文字
|
||||
/** Custom Chinese locale with modified Tour component button text */
|
||||
const customZhCN: Locale = {
|
||||
...zhCN,
|
||||
Tour: {
|
||||
@@ -31,7 +41,7 @@ const customZhCN: Locale = {
|
||||
},
|
||||
};
|
||||
|
||||
// 自定义英文 locale,修改 Tour 组件的按钮文字
|
||||
/** Custom English locale with modified Tour component button text */
|
||||
const customEnUS: Locale = {
|
||||
...enUS,
|
||||
Tour: {
|
||||
@@ -43,19 +53,27 @@ const customEnUS: Locale = {
|
||||
};
|
||||
|
||||
|
||||
/** Internationalization state interface */
|
||||
interface I18nState {
|
||||
/** Current language code */
|
||||
language: string;
|
||||
/** Ant Design locale object */
|
||||
locale: Locale;
|
||||
/** Current timezone */
|
||||
timeZone: string;
|
||||
/** Change application language */
|
||||
changeLanguage: (language: string) => void;
|
||||
/** Change timezone (triggers page reload) */
|
||||
changeTimeZone: (timeZone: string) => void;
|
||||
}
|
||||
|
||||
/** Initialize from localStorage or use defaults */
|
||||
const initialTimeZone = localStorage.getItem('timeZone') || 'Asia/Shanghai'
|
||||
const initialLanguage = localStorage.getItem('language') || 'en'
|
||||
const initialLocale = initialLanguage === 'en' ? customEnUS : customZhCN
|
||||
i18n.changeLanguage(initialLanguage)
|
||||
|
||||
/** Internationalization store */
|
||||
export const useI18n = create<I18nState>((set, get) => ({
|
||||
language: initialLanguage,
|
||||
locale: initialLocale,
|
||||
@@ -68,8 +86,9 @@ export const useI18n = create<I18nState>((set, get) => ({
|
||||
changeTimeZone: (timeZone: string) => {
|
||||
const { timeZone: lastTimeZone } = get()
|
||||
set({ timeZone })
|
||||
/** Reload page if timezone changed */
|
||||
if (lastTimeZone !== timeZone) {
|
||||
window.location.reload()
|
||||
}
|
||||
},
|
||||
}))
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user