🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(locale): align dayjs locale imports (#15896)
Innei2746a4b4543f
diff --git a/plugins/vite/sharedRendererConfig.ts b/plugins/vite/sharedRendererConfig.tsindex e5bc892f6b7..8e98d57a1d3 100644--- a/plugins/vite/sharedRendererConfig.ts+++ b/plugins/vite/sharedRendererConfig.ts@@ -267,24 +267,24 @@ export const sharedOptimizeDeps = {'i18next','react-i18next','dayjs',- 'dayjs/esm/locale/ar',- 'dayjs/esm/locale/bg',- 'dayjs/esm/locale/de',- 'dayjs/esm/locale/en',- 'dayjs/esm/locale/es',- 'dayjs/esm/locale/fa',- 'dayjs/esm/locale/fr',- 'dayjs/esm/locale/it',- 'dayjs/esm/locale/ja',- 'dayjs/esm/locale/ko',- 'dayjs/esm/locale/nl',- 'dayjs/esm/locale/pl',- 'dayjs/esm/locale/pt-br',- 'dayjs/esm/locale/ru',- 'dayjs/esm/locale/tr',- 'dayjs/esm/locale/vi',- 'dayjs/esm/locale/zh-cn',- 'dayjs/esm/locale/zh-tw',+ 'dayjs/locale/ar',+ 'dayjs/locale/bg',+ 'dayjs/locale/de',+ 'dayjs/locale/en',+ 'dayjs/locale/es',+ 'dayjs/locale/fa',+ 'dayjs/locale/fr',+ 'dayjs/locale/it',+ 'dayjs/locale/ja',+ 'dayjs/locale/ko',+ 'dayjs/locale/nl',+ 'dayjs/locale/pl',+ 'dayjs/locale/pt-br',+ 'dayjs/locale/ru',+ 'dayjs/locale/tr',+ 'dayjs/locale/vi',+ 'dayjs/locale/zh-cn',+ 'dayjs/locale/zh-tw','ahooks','motion/react',diff --git a/src/layout/SPAGlobalProvider/Locale.tsx b/src/layout/SPAGlobalProvider/Locale.tsxindex a0b001c0c10..ee875254867 100644--- a/src/layout/SPAGlobalProvider/Locale.tsx+++ b/src/layout/SPAGlobalProvider/Locale.tsx@@ -11,14 +11,13 @@ import { loadDayjsLocaleModule, normalizeDayjsLocale } from '@/utils/dayjsLocaleimport { getAntdLocale } from '@/utils/locale';const dayjsLocaleLoaders = import.meta.glob<{ default: ILocale }>(- '/node_modules/dayjs/esm/locale/{ar,bg,de,en,es,fa,fr,it,ja,ko,nl,pl,pt-br,ru,tr,vi,zh-cn,zh-tw}.js',+ '/node_modules/dayjs/locale/{ar,bg,de,en,es,fa,fr,it,ja,ko,nl,pl,pt-br,ru,tr,vi,zh-cn,zh-tw}.js',) as Record<string, DayjsLocaleGlobEntry>;const updateDayjs = async (lang: string) => {const locale = normalizeDayjsLocale(lang);- const key = `/node_modules/dayjs/esm/locale/${locale}.js`;- const loader =- dayjsLocaleLoaders[key] ?? dayjsLocaleLoaders['/node_modules/dayjs/esm/locale/en.js'];+ const key = `/node_modules/dayjs/locale/${locale}.js`;+ const loader = dayjsLocaleLoaders[key] ?? dayjsLocaleLoaders['/node_modules/dayjs/locale/en.js'];try {const mod = await loadDayjsLocaleModule(loader);@@ -28,7 +27,7 @@ const updateDayjs = async (lang: string) => {console.error('error', error);console.error(`dayjs locale for ${lang} not found, fallback to en`);const fallback = await loadDayjsLocaleModule(- dayjsLocaleLoaders['/node_modules/dayjs/esm/locale/en.js']!,+ dayjsLocaleLoaders['/node_modules/dayjs/locale/en.js']!,);dayjs.locale(fallback.default);}diff --git a/src/utils/dayjsLocale.test.ts b/src/utils/dayjsLocale.test.tsindex 46e4b9b5e04..1b7984fa308 100644--- a/src/utils/dayjsLocale.test.ts+++ b/src/utils/dayjsLocale.test.ts@@ -1,3 +1,4 @@+import dayjs from 'dayjs';import { describe, expect, it } from 'vitest';import { loadDayjsLocaleModule, normalizeDayjsLocale } from './dayjsLocale';@@ -32,4 +33,19 @@ describe('loadDayjsLocaleModule', () => {it('should return an eager glob locale module', async () => {await expect(loadDayjsLocaleModule(localeModule)).resolves.toBe(localeModule);});++ it('should load and apply a dayjs browser locale module', async () => {+ const previousLocale = dayjs.locale();+ const mod = await loadDayjsLocaleModule(+ () => import('dayjs/locale/zh-cn') as Promise<{ default: ILocale }>,+ );++ try {+ dayjs.locale(mod.default);++ expect(dayjs.locale()).toBe('zh-cn');+ } finally {+ dayjs.locale(previousLocale);+ }+ });});