更新国际化支持

This commit is contained in:
jxxghp
2025-04-28 15:12:07 +08:00
parent 308a8ab30d
commit 6be4694327
9 changed files with 1450 additions and 11 deletions

View File

@@ -14,6 +14,7 @@ import SubscribeEditDialog from '../dialog/SubscribeEditDialog.vue'
import SearchSiteDialog from '@/components/dialog/SearchSiteDialog.vue'
import SubscribeSeasonDialog from '../dialog/SubscribeSeasonDialog.vue'
import { useI18n } from 'vue-i18n'
import { getMeidaTypeText } from '@/types/i18n-type'
// 国际化
const { t } = useI18n()
@@ -486,7 +487,7 @@ function onRemoveSubscribe() {
:class="getChipColor(props.media?.type || '')"
class="absolute left-2 top-2 bg-opacity-80 text-white font-bold"
>
{{ props.media?.type }}
{{ getMeidaTypeText(props.media?.type) }}
</VChip>
<!-- 本地存在标识 -->
<ExistIcon v-if="isExists && !hover.isHovering" />

View File

@@ -22,6 +22,13 @@ export default {
saving: 'Saving',
reset: 'Reset',
},
mediaType: {
movie: 'Movie',
tv: 'TV Show',
anime: 'Anime',
collection: 'Collection',
unknown: 'Unknown',
},
theme: {
light: 'Light',
dark: 'Dark',

View File

@@ -22,6 +22,13 @@ export default {
saving: '保存中',
reset: '重置',
},
mediaType: {
movie: '电影',
tv: '电视剧',
anime: '动漫',
collection: '合集',
unknown: '未知',
},
theme: {
light: '浅色',
dark: '深色',

1401
src/locales/zh-TW.ts Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -4,6 +4,7 @@ import { SUPPORTED_LOCALES, SupportedLocale } from '@/types/i18n'
// 导入语言文件
import zhCN from '@/locales/zh-CN'
import zhTW from '@/locales/zh-TW'
import enUS from '@/locales/en-US'
// 创建 i18n 实例
@@ -13,6 +14,7 @@ const i18n = createI18n({
fallbackLocale: 'zh-CN', // 回退语言
messages: {
'zh-CN': zhCN,
'zh-TW': zhTW,
'en-US': enUS,
},
silentTranslationWarn: true,

View File

@@ -1 +0,0 @@

23
src/types/i18n-type.ts Normal file
View File

@@ -0,0 +1,23 @@
// 将中文标签转换为当前语言的标签
export function getMeidaTypeText(label: string | undefined) {
if (!label) return ''
const { t } = useI18n()
// 常见的媒体类型及其映射
const typeMap: Record<string, string> = {
'电影': 'mediaType.movie',
'电视剧': 'mediaType.tv',
'动漫': 'mediaType.anime',
'合集': 'mediaType.collection',
'未知': 'mediaType.unknown',
}
// 如果是已知类型使用i18n翻译
if (label in typeMap) {
return t(typeMap[label])
}
// 对于未知的类型,直接返回原始标签
return label
}

View File

@@ -1,9 +1,3 @@
import zhCN from '@/locales/zh-CN'
// 导出类型和常量,而不是作为语言消息文件
export type MessageSchema = typeof zhCN
export type LocaleKey = keyof typeof zhCN
export interface LocaleInfo {
name: string
title: string
@@ -16,6 +10,11 @@ export const SUPPORTED_LOCALES: Record<string, LocaleInfo> = {
title: '简体中文',
flag: '🇨🇳',
},
'zh-TW': {
name: 'zh-TW',
title: '繁體中文',
flag: '🇨🇳',
},
'en-US': {
name: 'en-US',
title: 'English',

View File

@@ -3,8 +3,8 @@
"baseUrl": "./",
"target": "esnext",
"useDefineForClassFields": true,
"module": "Node16",
"moduleResolution": "node16",
"module": "ESNext",
"moduleResolution": "bundler",
"isolatedModules": true,
"strict": true,
"jsx": "preserve",
@@ -73,4 +73,4 @@
"node_modules",
"src/@iconify/*"
]
}
}