@@ -323,13 +323,59 @@ class LyricsContainer extends react.Component {
323
323
if ( CACHE [ info . uri ] ?. [ CONFIG . modes [ mode ] ] ) {
324
324
this . resetDelay ( ) ;
325
325
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
+ }
326
349
this . translateLyrics ( ) ;
327
350
return ;
328
351
}
329
352
} else {
330
353
if ( CACHE [ info . uri ] ) {
331
354
this . resetDelay ( ) ;
332
355
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
+ }
333
379
this . translateLyrics ( ) ;
334
380
return ;
335
381
}
@@ -385,16 +431,15 @@ class LyricsContainer extends react.Component {
385
431
386
432
// Seemingly long delay so it can be cleared later for accurate timing
387
433
showNotification ( 10000 ) ;
388
- const lyricText = lyrics . map ( lyric => lyric . text ) . join ( "\n" ) ;
389
-
390
434
for ( const params of [
391
435
[ "romaji" , "spaced" , "romaji" ] ,
392
436
[ "hiragana" , "furigana" , "furigana" ] ,
393
437
[ "hiragana" , "normal" , "hiragana" ] ,
394
438
[ "katakana" , "normal" , "katakana" ]
395
439
] ) {
396
440
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" ) ;
398
443
Utils . processTranslatedLyrics ( result , lyrics , { state : this . state , stateName : params [ 2 ] } ) ;
399
444
showNotification ( 200 ) ;
400
445
lyricContainerUpdate ?. ( ) ;
@@ -406,7 +451,8 @@ class LyricsContainer extends react.Component {
406
451
[ "romaja" , "romaja" ]
407
452
] ) {
408
453
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" ) ;
410
456
Utils . processTranslatedLyrics ( result , lyrics , { state : this . state , stateName : params [ 1 ] } ) ;
411
457
showNotification ( 200 ) ;
412
458
lyricContainerUpdate ?. ( ) ;
@@ -421,7 +467,8 @@ class LyricsContainer extends react.Component {
421
467
[ "t" , "tw" ]
422
468
] ) {
423
469
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" ) ;
425
472
Utils . processTranslatedLyrics ( result , lyrics , { state : this . state , stateName : params [ 1 ] } ) ;
426
473
showNotification ( 200 ) ;
427
474
lyricContainerUpdate ?. ( ) ;
0 commit comments