[+] i18n for progress
This commit is contained in:
+8
-2
@@ -103,6 +103,13 @@ export default {
|
|||||||
wrong: 'Wrong: ',
|
wrong: 'Wrong: ',
|
||||||
remaining: 'Remaining: '
|
remaining: 'Remaining: '
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
prepare: {
|
||||||
|
lyrics: 'Fetching lyrics from NetEase',
|
||||||
|
ai: 'AI analyzing lyrics',
|
||||||
|
music: 'Fetching music from NetEase',
|
||||||
|
separation: 'AI vocal separation',
|
||||||
|
error: 'Error: '
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
user: {
|
user: {
|
||||||
@@ -159,6 +166,5 @@ export default {
|
|||||||
title: 'Error',
|
title: 'Error',
|
||||||
refresh: 'Refresh to Retry'
|
refresh: 'Refresh to Retry'
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
components: {}
|
|
||||||
}
|
}
|
||||||
@@ -31,6 +31,11 @@ export const setLanguage = (lang: Lang) => {
|
|||||||
location.reload()
|
location.reload()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const useMsg = () => {
|
||||||
|
const i18n = getI18n()
|
||||||
|
return (key: string) => key.split('.').reduce((o, i) => (o as any)?.[i], i18n) as unknown as string
|
||||||
|
}
|
||||||
|
|
||||||
export {}
|
export {}
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
|
|||||||
+8
-2
@@ -103,6 +103,13 @@ export default {
|
|||||||
wrong: '不正解:',
|
wrong: '不正解:',
|
||||||
remaining: '残り:'
|
remaining: '残り:'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
prepare: {
|
||||||
|
lyrics: 'NetEaseから歌詞を取得中',
|
||||||
|
ai: 'AIが歌詞を分析中',
|
||||||
|
music: 'NetEaseから音楽を取得中',
|
||||||
|
separation: 'AIボーカル分離',
|
||||||
|
error: 'エラー: '
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
user: {
|
user: {
|
||||||
@@ -159,6 +166,5 @@ export default {
|
|||||||
title: 'エラー',
|
title: 'エラー',
|
||||||
refresh: '更新して再試行'
|
refresh: '更新して再試行'
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
components: {}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-3
@@ -103,6 +103,13 @@ export default {
|
|||||||
wrong: '错误:',
|
wrong: '错误:',
|
||||||
remaining: '剩余:'
|
remaining: '剩余:'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
prepare: {
|
||||||
|
lyrics: '从网易云获取歌词',
|
||||||
|
ai: 'AI 标注歌词读音',
|
||||||
|
music: '从网易云获取音乐',
|
||||||
|
separation: 'AI 人声分离',
|
||||||
|
error: '错误: '
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
user: {
|
user: {
|
||||||
@@ -159,8 +166,5 @@ export default {
|
|||||||
title: '错误',
|
title: '错误',
|
||||||
refresh: '刷新重试'
|
refresh: '刷新重试'
|
||||||
}
|
}
|
||||||
},
|
|
||||||
components: {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -155,14 +155,14 @@ export const prepareSong = async (songId: number) => {
|
|||||||
const addTask = (id: string, task: string) => ({ id, task, progress: 0 }).also(it => state.items.push(it))
|
const addTask = (id: string, task: string) => ({ id, task, progress: 0 }).also(it => state.items.push(it))
|
||||||
const processLyrics = async () => {
|
const processLyrics = async () => {
|
||||||
// 1. Get Lyrics
|
// 1. Get Lyrics
|
||||||
const taskLyrics = addTask('lyrics', '从网易云获取歌词')
|
const taskLyrics = addTask('lyrics', 'lyrics')
|
||||||
const raw = await getLyricsRaw(songId)
|
const raw = await getLyricsRaw(songId)
|
||||||
taskLyrics.progress = 1
|
taskLyrics.progress = 1
|
||||||
|
|
||||||
if (raw.lang !== 'jpn') throw new Error('不是日语歌曲')
|
if (raw.lang !== 'jpn') throw new Error('不是日语歌曲')
|
||||||
|
|
||||||
// 2. AI Process
|
// 2. AI Process
|
||||||
const taskAI = addTask('ai', 'AI 标注歌词读音')
|
const taskAI = addTask('ai', 'ai')
|
||||||
|
|
||||||
// Check cache
|
// Check cache
|
||||||
if (await checkLyricsProcessed(songId)) taskAI.progress = 1
|
if (await checkLyricsProcessed(songId)) taskAI.progress = 1
|
||||||
@@ -175,12 +175,12 @@ export const prepareSong = async (songId: number) => {
|
|||||||
|
|
||||||
const processMusic = async () => {
|
const processMusic = async () => {
|
||||||
// 3. Audio
|
// 3. Audio
|
||||||
const taskAudio = addTask('music', '从网易云获取音乐')
|
const taskAudio = addTask('music', 'music')
|
||||||
await getSongUrl(songId)
|
await getSongUrl(songId)
|
||||||
taskAudio.progress = 1
|
taskAudio.progress = 1
|
||||||
|
|
||||||
// 4. Source Separation
|
// 4. Source Separation
|
||||||
const taskSeparation = addTask('separation', 'AI 人声分离')
|
const taskSeparation = addTask('separation', 'separation')
|
||||||
const inputPath = path.join(CACHE_DIR, `${songId}/exhigh.mp3`)
|
const inputPath = path.join(CACHE_DIR, `${songId}/exhigh.mp3`)
|
||||||
const outputDir = path.join(CACHE_DIR, `${songId}`)
|
const outputDir = path.join(CACHE_DIR, `${songId}`)
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ export const prepareSong = async (songId: number) => {
|
|||||||
await separateSong(inputPath, outputDir)
|
await separateSong(inputPath, outputDir)
|
||||||
taskSeparation.progress = 1
|
taskSeparation.progress = 1
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
addTask('error', `错误: ${e.message}`).progress = -1
|
addTask('error', e.message).progress = -1
|
||||||
// Don't fail the whole process, just this step
|
// Don't fail the whole process, just this step
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,7 +197,7 @@ export const prepareSong = async (songId: number) => {
|
|||||||
await Promise.all([processLyrics(), processMusic()])
|
await Promise.all([processLyrics(), processMusic()])
|
||||||
state.status = 'done'
|
state.status = 'done'
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
addTask('error', `错误: ${eToString(e)}`).progress = -1
|
addTask('error', eToString(e)).progress = -1
|
||||||
state.status = 'error'
|
state.status = 'error'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,12 @@
|
|||||||
import PlayerAppBar from "$lib/ui/player/PlayerAppBar.svelte"
|
import PlayerAppBar from "$lib/ui/player/PlayerAppBar.svelte"
|
||||||
import ProgressList from "$lib/ui/ProgressList.svelte"
|
import ProgressList from "$lib/ui/ProgressList.svelte"
|
||||||
import { goto } from "$app/navigation"
|
import { goto } from "$app/navigation"
|
||||||
import { artistAndAlbum } from "$lib/utils"
|
import { getI18n, useMsg } from "$lib/i18n"
|
||||||
import { getI18n } from "$lib/i18n"
|
|
||||||
import { typingSettingsDefault } from "$lib/types"
|
import { typingSettingsDefault } from "$lib/types"
|
||||||
import { getNextSong } from "$lib/ui/player/SongSwitching.js";
|
import { getNextSong } from "$lib/ui/player/SongSwitching.js"
|
||||||
|
|
||||||
const t = getI18n().song.mode
|
const t = getI18n().song.mode
|
||||||
|
const getMsg = useMsg()
|
||||||
|
|
||||||
let { data } = $props()
|
let { data } = $props()
|
||||||
|
|
||||||
@@ -52,24 +52,31 @@
|
|||||||
const state = res.status
|
const state = res.status
|
||||||
|
|
||||||
if (state && state.items) {
|
if (state && state.items) {
|
||||||
// Update task status
|
// Update task status
|
||||||
for (const item of state.items) {
|
for (const item of state.items) {
|
||||||
if (item.progress !== 1) continue
|
if (item.progress !== 1) continue
|
||||||
if (item.id === 'lyrics') taskStatus.lyrics = true
|
if (item.id === 'lyrics') taskStatus.lyrics = true
|
||||||
if (item.id === 'ai') taskStatus.ai = true
|
if (item.id === 'ai') taskStatus.ai = true
|
||||||
if (item.id === 'music') taskStatus.music = true
|
if (item.id === 'music') taskStatus.music = true
|
||||||
if (item.id === 'separation') taskStatus.separation = true
|
if (item.id === 'separation') taskStatus.separation = true
|
||||||
|
}
|
||||||
|
|
||||||
|
progressItems = state.items.map((item: any) => {
|
||||||
|
let taskName = getMsg(`song.prepare.${item.id}`) || item.task
|
||||||
|
if (item.id === 'error') {
|
||||||
|
taskName = getMsg('song.prepare.error') + item.task
|
||||||
}
|
}
|
||||||
|
|
||||||
progressItems = state.items.map((item: any) => ({
|
return {
|
||||||
title: item.task + (item.progress > 0 && item.progress < 1 ? ` (${Math.round(item.progress * 100)}%)` : ''),
|
title: taskName + (item.progress > 0 && item.progress < 1 ? ` (${Math.round(item.progress * 100)}%)` : ''),
|
||||||
icon: item.progress === 1 ? 'i-material-symbols:check text-green-500' :
|
icon: item.progress === 1 ? 'i-material-symbols:check text-green-500' :
|
||||||
item.progress === -1 ? 'i-material-symbols:error text-red-500' :
|
item.progress === -1 ? 'i-material-symbols:error text-red-500' :
|
||||||
'i-material-symbols:sync animate-spin'
|
'i-material-symbols:sync animate-spin'
|
||||||
}))
|
}
|
||||||
|
})
|
||||||
const totalProgress = state.items.reduce((acc: number, cur: any) => acc + Math.max(0, cur.progress), 0)
|
|
||||||
progressPercentage = Math.min(100, Math.round((totalProgress / 4) * 100))
|
const totalProgress = state.items.reduce((acc: number, cur: any) => acc + Math.max(0, cur.progress), 0)
|
||||||
|
progressPercentage = Math.min(100, Math.round((totalProgress / 4) * 100))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.status === "done") {
|
if (state.status === "done") {
|
||||||
|
|||||||
Reference in New Issue
Block a user