@@ -323,13 +323,59 @@ class LyricsContainer extends react.Component {
323323 if ( CACHE [ info . uri ] ?. [ CONFIG . modes [ mode ] ] ) {
324324 this . resetDelay ( ) ;
325325 this . setState ( { ...CACHE [ info . uri ] , isCached } ) ;
326+ {
327+ let mode = - 1 ;
328+ if ( this . state . explicitMode !== - 1 ) {
329+ mode = this . state . explicitMode ;
330+ } else if ( this . state . lockMode !== - 1 ) {
331+ mode = this . state . lockMode ;
332+ } else {
333+ // Auto switch
334+ if ( this . state . karaoke ) {
335+ mode = KARAOKE ;
336+ } else if ( this . state . synced ) {
337+ mode = SYNCED ;
338+ } else if ( this . state . unsynced ) {
339+ mode = UNSYNCED ;
340+ } else if ( this . state . genius ) {
341+ mode = GENIUS ;
342+ }
343+ }
344+ const lyricsState = CACHE [ info . uri ] [ CONFIG . modes [ mode ] ] ;
345+ if ( lyricsState ) {
346+ this . state . currentLyrics = this . state [ CONFIG . visual [ "translate:translated-lyrics-source" ] ] ?? lyricsState ;
347+ }
348+ }
326349 this . translateLyrics ( ) ;
327350 return ;
328351 }
329352 } else {
330353 if ( CACHE [ info . uri ] ) {
331354 this . resetDelay ( ) ;
332355 this . setState ( { ...CACHE [ info . uri ] , isCached } ) ;
356+ {
357+ let mode = - 1 ;
358+ if ( this . state . explicitMode !== - 1 ) {
359+ mode = this . state . explicitMode ;
360+ } else if ( this . state . lockMode !== - 1 ) {
361+ mode = this . state . lockMode ;
362+ } else {
363+ // Auto switch
364+ if ( this . state . karaoke ) {
365+ mode = KARAOKE ;
366+ } else if ( this . state . synced ) {
367+ mode = SYNCED ;
368+ } else if ( this . state . unsynced ) {
369+ mode = UNSYNCED ;
370+ } else if ( this . state . genius ) {
371+ mode = GENIUS ;
372+ }
373+ }
374+ const lyricsState = CACHE [ info . uri ] [ CONFIG . modes [ mode ] ] ;
375+ if ( lyricsState ) {
376+ this . state . currentLyrics = this . state [ CONFIG . visual [ "translate:translated-lyrics-source" ] ] ?? lyricsState ;
377+ }
378+ }
333379 this . translateLyrics ( ) ;
334380 return ;
335381 }
@@ -385,16 +431,15 @@ class LyricsContainer extends react.Component {
385431
386432 // Seemingly long delay so it can be cleared later for accurate timing
387433 showNotification ( 10000 ) ;
388- const lyricText = lyrics . map ( lyric => lyric . text ) . join ( "\n" ) ;
389-
390434 for ( const params of [
391435 [ "romaji" , "spaced" , "romaji" ] ,
392436 [ "hiragana" , "furigana" , "furigana" ] ,
393437 [ "hiragana" , "normal" , "hiragana" ] ,
394438 [ "katakana" , "normal" , "katakana" ]
395439 ] ) {
396440 if ( language !== "ja" ) continue ;
397- this . translator . romajifyText ( lyricText , params [ 0 ] , params [ 1 ] ) . then ( result => {
441+ Promise . all ( lyrics . map ( lyric => this . translator . romajifyText ( lyric . text , params [ 0 ] , params [ 1 ] ) ) ) . then ( results => {
442+ const result = results . join ( "\n" ) ;
398443 Utils . processTranslatedLyrics ( result , lyrics , { state : this . state , stateName : params [ 2 ] } ) ;
399444 showNotification ( 200 ) ;
400445 lyricContainerUpdate ?. ( ) ;
@@ -406,7 +451,8 @@ class LyricsContainer extends react.Component {
406451 [ "romaja" , "romaja" ]
407452 ] ) {
408453 if ( language !== "ko" ) continue ;
409- this . translator . convertToRomaja ( lyricText , params [ 1 ] ) . then ( result => {
454+ Promise . all ( lyrics . map ( lyric => this . translator . convertToRomaja ( lyric . text , params [ 1 ] ) ) ) . then ( results => {
455+ const result = results . join ( "\n" ) ;
410456 Utils . processTranslatedLyrics ( result , lyrics , { state : this . state , stateName : params [ 1 ] } ) ;
411457 showNotification ( 200 ) ;
412458 lyricContainerUpdate ?. ( ) ;
@@ -421,7 +467,8 @@ class LyricsContainer extends react.Component {
421467 [ "t" , "tw" ]
422468 ] ) {
423469 if ( ! language . includes ( "zh" ) || ( language === "zh-hans" && params [ 0 ] === "t" ) || ( language === "zh-hant" && params [ 0 ] === "cn" ) ) continue ;
424- this . translator . convertChinese ( lyricText , params [ 0 ] , params [ 1 ] ) . then ( result => {
470+ Promise . all ( lyrics . map ( lyric => this . translator . convertChinese ( lyric . text , params [ 0 ] , params [ 1 ] ) ) ) . then ( results => {
471+ const result = results . join ( "\n" ) ;
425472 Utils . processTranslatedLyrics ( result , lyrics , { state : this . state , stateName : params [ 1 ] } ) ;
426473 showNotification ( 200 ) ;
427474 lyricContainerUpdate ?. ( ) ;
0 commit comments