Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,16 @@ class DeeplEngine : TranslationEngine(
}

override suspend fun translate(query: String, source: String, target: String): Translation {
val convertedTarget = when(target){
"zh-Hant", "zh-Hans" -> "zh"
else -> target
}

if (getApiKey().isNotEmpty()) {
val response = api.translate(
apiKeyString,
sourceOrAuto(source.uppercase()),
target.uppercase(),
convertedTarget.uppercase(),
query
)

Expand All @@ -130,7 +135,7 @@ class DeeplEngine : TranslationEngine(
),
splitting = "newlines",
lang = DeeplWebTranslationRequestParamsLang(
targetLang = target.uppercase(),
targetLang = convertedTarget.uppercase(),
sourceLangUserSelected = sourceOrAuto(source.uppercase()).ifEmpty { "auto" },
preference = DeeplWebTranslationRequestParamsLangPreference(
weight = emptyMap()
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/com/bnyro/translate/api/gl/GlEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,15 @@ class GlEngine : TranslationEngine(
).map { Language(it.first.trim(), it.second) }
}

protected fun convertLanguageCode(languageCode: String): String {
return when(languageCode){
"zh-Hant", "zh-Hans" -> "zh"
else -> languageCode
}
}

override suspend fun translate(query: String, source: String, target: String): Translation {
val translation = api.translate(source, target, query)
val translation = api.translate(convertLanguageCode(source), convertLanguageCode(target), query)
return Translation(translation.translation)
}
}
11 changes: 9 additions & 2 deletions app/src/main/java/com/bnyro/translate/api/lv/LVEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,17 @@ class LVEngine : TranslationEngine(
}
}

protected fun convertLanguageCode(languageCode: String): String {
return when(languageCode){
"zh-Hant", "zh-Hans" -> "zh"
else -> languageCode
}
}

override suspend fun translate(query: String, source: String, target: String): Translation {
val response = api.translate(
sourceOrAuto(source),
target,
convertLanguageCode(sourceOrAuto(source)),
convertLanguageCode(target),
query.replace("/", "")
)
return Translation(
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/com/bnyro/translate/api/mh/MhEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,20 @@ class MhEngine : TranslationEngine(
.map { Language(it.id, it.name) }
}

protected fun convertLanguageCode(languageCode: String): String {
return when(languageCode){
"zh-Hant" -> "zh-TW"
"zh-Hans" -> "zh-CN"
else -> languageCode
}
}

override suspend fun translate(query: String, source: String, target: String): Translation {
val response = api.translate(
engine = getSelectedEngine(),
source = sourceOrAuto(source.take(2)),
source = convertLanguageCode(sourceOrAuto(source)),
query = query,
target = target.take(2),
target = convertLanguageCode(target),
)
return Translation(
translatedText = response.translatedText,
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/com/bnyro/translate/api/wm/WmEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,15 @@ class WmEngine : TranslationEngine(
}
}

protected fun convertLanguageCode(languageCode: String): String {
return when(languageCode){
"zh-Hant", "zh-Hans" -> "zh"
else -> languageCode
}
}

override suspend fun translate(query: String, source: String, target: String): Translation {
val response = api.translate(source, target, WmTranslationRequest(query))
val response = api.translate(convertLanguageCode(source), convertLanguageCode(target), WmTranslationRequest(query))
return Translation(response.translation)
}
}
11 changes: 10 additions & 1 deletion app/src/main/java/com/bnyro/translate/api/ya/YandexEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,17 @@ class YandexEngine : TranslationEngine(
).map { (key, value) -> Language(code = key, name = value) }
}

protected fun convertLanguageCode(languageCode: String): String {
return when(languageCode){
"zh-Hant", "zh-Hans" -> "zh"
else -> languageCode
}
}

override suspend fun translate(query: String, source: String, target: String): Translation {
val lang = if (source.isEmpty()) target else "$source-$target"
val convertedSource = convertLanguageCode(source)
val convertedTarget = convertLanguageCode(target)
val lang = if (convertedSource.isEmpty()) convertedTarget else "$convertedSource-$convertedTarget"

val uuid = UUID.randomUUID().toString().replace("-", "") + "-0-0"
val response = api.translate(lang, query, "android", uuid)
Expand Down