Skip to content

Commit

Permalink
Merge pull request #4457 from aneesh1122/master
Browse files Browse the repository at this point in the history
improved lyrics translations
  • Loading branch information
fast4x authored Nov 11, 2024
2 parents f95ed01 + 7396bde commit 51e4c51
Showing 1 changed file with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ fun Lyrics(
val result = withContext(Dispatchers.IO) {
try {
var translation: Translation?
var translation2: Translation?
if(destinationLanguage == Language.AUTO){
translation = translator.translate(
textToTranslate,
Expand All @@ -350,12 +351,17 @@ fun Lyrics(
destLanguage,
Language.AUTO
)
translation2 = translator.translate(
textToTranslate,
translation.sourceLanguage,
translation.sourceLanguage
)
val outputText = if(romanizationEnabeled){
translation.pronunciation ?: translation.translatedText
if (showSecondLine && isSync) {(translation2.pronunciation ?: translation2.sourceText) + "\\n[${translation.translatedText}]"} else translation.pronunciation ?: translation.translatedText
}else{
translation.translatedText
if (showSecondLine && isSync) {textToTranslate + "\\n[${translation.translatedText}]"} else translation.translatedText
}
outputText.replace("\\r","\r")
outputText.replace("\\r","\r").replace("\\n","\n")
} catch (e: Exception) {
if(isSync){
Timber.e("Lyrics sync translation ${e.stackTraceToString()}")
Expand Down Expand Up @@ -737,7 +743,7 @@ fun Lyrics(
items = synchronizedLyrics.sentences
) { index, sentence ->
var translatedText by remember { mutableStateOf("") }
if (translateEnabled && !showSecondLine) {
if (translateEnabled) {
val mutState = remember { mutableStateOf("") }
translateLyricsWithRomanization(mutState, sentence.second, true, languageDestination)()
translatedText = mutState.value
Expand All @@ -751,11 +757,6 @@ fun Lyrics(
}
}

val mutState1 = remember { mutableStateOf("") }
var translatedText2 by remember { mutableStateOf("") }
translateLyricsWithRomanization(mutState1, sentence.second, true, languageDestination)()
translatedText2 = mutState1.value

//Rainbow Shimmer
val infiniteTransition = rememberInfiniteTransition()

Expand Down Expand Up @@ -874,7 +875,7 @@ fun Lyrics(
) {
if (showlyricsthumbnail)
BasicText(
text = (translatedText + if (showSecondLine && translateEnabled && translatedText != "") {"\\n[$translatedText2]"} else "").replace("\\n","\n"),
text = translatedText,
style = TextStyle (
textAlign = lyricsAlignment.selected,
).merge(
Expand Down Expand Up @@ -908,7 +909,7 @@ fun Lyrics(
)
else if ((lyricsColor == LyricsColor.White) || (lyricsColor == LyricsColor.Black) || (lyricsColor == LyricsColor.Accent) || (lyricsColor == LyricsColor.Thememode))
BasicText(
text = (translatedText + if (showSecondLine && translateEnabled && translatedText != "") {"\\n[$translatedText2]"} else "").replace("\\n","\n"),
text = translatedText,
style = TextStyle (
textAlign = lyricsAlignment.selected,
).merge(
Expand Down Expand Up @@ -1007,7 +1008,7 @@ fun Lyrics(
)
else
BasicText(
text = (translatedText + if (showSecondLine && translateEnabled && translatedText != "") {"\\n[$translatedText2]"} else "").replace("\\n","\n"),
text = translatedText,
style = TextStyle(
textAlign = lyricsAlignment.selected,
brush = if (colorPaletteMode == ColorPaletteMode.Light) brushrainbow else brushrainbowdark
Expand Down Expand Up @@ -1086,7 +1087,7 @@ fun Lyrics(

} else if ((lyricsOutline == LyricsOutline.White) || (lyricsOutline == LyricsOutline.Black) || (lyricsOutline == LyricsOutline.Thememode))
BasicText(
text = (translatedText + if (showSecondLine && translateEnabled && translatedText != "") {"\\n[$translatedText2]"} else "").replace("\\n","\n"),
text = translatedText,
style = TextStyle(
textAlign = lyricsAlignment.selected,
drawStyle = Stroke(
Expand Down Expand Up @@ -1224,7 +1225,7 @@ fun Lyrics(
)
else if (lyricsOutline == LyricsOutline.Rainbow)
BasicText(
text = (translatedText + if (showSecondLine && translateEnabled && translatedText != "") {"\\n[$translatedText2]"} else "").replace("\\n","\n"),
text = translatedText,
style = TextStyle(
textAlign = lyricsAlignment.selected,
brush = brushrainbowdark,
Expand Down Expand Up @@ -1271,7 +1272,7 @@ fun Lyrics(
)
else //For Glow Outline//
BasicText(
text = (translatedText + if (showSecondLine && translateEnabled && translatedText != "") {"\\n[$translatedText2]"} else "").replace("\\n","\n"),
text = translatedText,
style = TextStyle(
textAlign = lyricsAlignment.selected,
shadow = Shadow(
Expand Down

0 comments on commit 51e4c51

Please sign in to comment.