Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add source text pronunciation. #7

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/kotlin/me/bush/translator/Translation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ class Translation internal constructor(
*/
val pronunciation = jsonData[0].jsonArray.last().jsonArray[2].string

/**
* The pronunciation of the source text. This is generally
* null when the source language uses the Roman/Latin Alphabet.
*/
val pronunciationSource = run {
val jsonArray = jsonData[0].jsonArray.last().jsonArray
if (jsonArray.size > 3) {
jsonArray[3].string
} else {
null
}
}

/**
* The language of the translated text. This is useful
* if the source language was set to [Language.AUTO].
Expand Down
3 changes: 2 additions & 1 deletion src/test/kotlin/TranslatorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TranslatorTest {
Goin' a lil KOOKY… He's off the walls! Bananas! Loco! You want me to stop. Isn't that wonderful. Well
lemme just do whatever you say, because it's your little fairy tale.
""".trimIndent(),
target = Language.values().filter { it != Language.ENGLISH }.random(),
target = Language.entries.filter { it != Language.ENGLISH && it != Language.AUTO }.random(),
source = Language.AUTO
)
println(translation.url)
Expand All @@ -31,5 +31,6 @@ class TranslatorTest {
println(translation.targetLanguage)
println(translation.sourceLanguage)
println(translation.pronunciation)
println(translation.pronunciationSource)
}
}