import type { IDataSourceItem } from '@/types'; import { getLang, type TLanguage } from '@cainiaofe/cn-i18n'; function i18nList(list: IDataSourceItem[], currentLang: TLanguage) { if (!Array.isArray(list)) return; for (const item of list) { if (item && item.i18n && item.label) { item.label = item.i18n[currentLang] || item.label; if (item.children?.length) { i18nList(item.children, currentLang); } } } } /** * dataSource 国际化处理 * 该方法会根据当前语言更新数据源的标签,会修改原始数据源,不会返回新的引用对象,同时返回原始数据源 */ export function dataSourceI18n(dataSource: IDataSourceItem[]) { const currentLang = getLang(); i18nList(dataSource || [], currentLang); return dataSource; }