You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
917 B
28 lines
917 B
4 weeks ago
|
import { getCurrentLanguage } from '../i18n';
|
||
|
|
||
|
export const getSystemLanguage = <T extends Record<string, any>>(data: T): string => {
|
||
|
// 获取当前i18n语言
|
||
|
const currentLang = getCurrentLanguage();
|
||
|
|
||
|
// 特殊处理中文
|
||
|
if (currentLang === 'zh' && 'subject' in data) {
|
||
|
return data.subject as string;
|
||
|
}
|
||
|
|
||
|
// 获取所有subject_trans开头的字段
|
||
|
const translationFields = Object.keys(data).filter(key =>
|
||
|
key.startsWith('subject_trans')
|
||
|
);
|
||
|
|
||
|
// 查找匹配的字段
|
||
|
const matchedField = translationFields.find(field => {
|
||
|
// 从字段名中提取语言代码
|
||
|
const langCode = field.replace('subject_trans_', '');
|
||
|
// 如果没有后缀,则为法语
|
||
|
return langCode === '' ? currentLang === 'fr' : langCode === currentLang;
|
||
|
});
|
||
|
|
||
|
// 返回匹配的翻译值,如果没有匹配则返回法语
|
||
|
return (data[matchedField || 'subject_trans'] as string) || '';
|
||
|
};
|