diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index b86273d94..b589d56e9 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 7b3006b6e..ad84da2a6 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -6,7 +6,7 @@
-
+
-
+
diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json
index e3ef54f00..83aab6d5b 100644
--- a/app/release/output-metadata.json
+++ b/app/release/output-metadata.json
@@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
- "versionCode": 41,
- "versionName": "10.0",
+ "versionCode": 42,
+ "versionName": "11.0",
"outputFile": "app-release.apk"
}
],
diff --git a/app/src/main/java/com/bnyro/translate/api/mh/MhEngine.kt b/app/src/main/java/com/bnyro/translate/api/mh/MhEngine.kt
index 0283084c1..0cc482f91 100644
--- a/app/src/main/java/com/bnyro/translate/api/mh/MhEngine.kt
+++ b/app/src/main/java/com/bnyro/translate/api/mh/MhEngine.kt
@@ -19,6 +19,7 @@ package com.bnyro.translate.api.mh
import com.bnyro.translate.const.ApiKeyState
import com.bnyro.translate.db.obj.Language
+import com.bnyro.translate.obj.Definition
import com.bnyro.translate.obj.Translation
import com.bnyro.translate.util.RetrofitHelper
import com.bnyro.translate.util.TranslationEngine
@@ -45,7 +46,8 @@ class MhEngine : TranslationEngine(
supportsAudio = true
) {
lateinit var api: Mozhi
-
+ private val transliterationFailedRegex = Regex("Direction \'\\w{2}\' is not supported")
+ private val bracketRegex = Regex("[<>]")
override fun createOrRecreate(): TranslationEngine = apply {
api = RetrofitHelper.createApi(this)
@@ -65,7 +67,23 @@ class MhEngine : TranslationEngine(
)
return Translation(
translatedText = response.translatedText,
- detectedLanguage = response.detectedLanguage
+ transliterations = listOf(
+ response.sourceTransliteration,
+ response.targetTransliteration
+ ).filter {
+ it.isNotBlank() && !it.matches(transliterationFailedRegex)
+ },
+ detectedLanguage = response.detectedLanguage.takeIf { !it.isNullOrBlank() },
+ definitions = response.wordChoices.orEmpty().map { definition ->
+ Definition(
+ definition = definition.definition.takeIf { it.isNotBlank() },
+ example = definition.example.takeIf { it.isNotBlank() }
+ )
+ },
+ similar = response.targetSynonyms,
+ examples = response.wordChoices.orEmpty()
+ .flatMap { it.examplesSource.orEmpty() + it.examplesTarget.orEmpty() }
+ .map { it.replace(bracketRegex, "") }
)
}
diff --git a/app/src/main/java/com/bnyro/translate/api/mh/obj/MhTranslationResponse.kt b/app/src/main/java/com/bnyro/translate/api/mh/obj/MhTranslationResponse.kt
index 56e21fbdb..5a40ce739 100644
--- a/app/src/main/java/com/bnyro/translate/api/mh/obj/MhTranslationResponse.kt
+++ b/app/src/main/java/com/bnyro/translate/api/mh/obj/MhTranslationResponse.kt
@@ -17,18 +17,20 @@
package com.bnyro.translate.api.mh.obj
-import com.bnyro.translate.api.st.obj.STDefinition
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
-data class MhTranslationResponse (
- @SerialName("definitions")
- val definitions: STDefinition? = null,
+data class MhTranslationResponse(
@SerialName("pronunciation")
val pronunciation: String? = null,
@SerialName("detected")
val detectedLanguage: String? = null,
@SerialName("translated-text")
- val translatedText: String = ""
-)
+ val translatedText: String = "",
+ @SerialName("source_synonyms") val sourceSynonyms: List?,
+ @SerialName("source_transliteration") val sourceTransliteration: String,
+ @SerialName("target_synonyms") val targetSynonyms: List?,
+ @SerialName("target_transliteration") val targetTransliteration: String,
+ @SerialName("word_choices") val wordChoices: List? = null
+)
\ No newline at end of file
diff --git a/app/src/main/java/com/bnyro/translate/api/mh/obj/WordChoice.kt b/app/src/main/java/com/bnyro/translate/api/mh/obj/WordChoice.kt
new file mode 100644
index 000000000..081e97222
--- /dev/null
+++ b/app/src/main/java/com/bnyro/translate/api/mh/obj/WordChoice.kt
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2024 You Apps
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package com.bnyro.translate.api.mh.obj
+
+import kotlinx.serialization.SerialName
+import kotlinx.serialization.Serializable
+
+@Serializable
+data class WordChoice(
+ val definition: String,
+ val example: String,
+ val word: String,
+ @SerialName("examples_source") val examplesSource: List? = null,
+ @SerialName("examples_target") val examplesTarget: List? = null,
+)
\ No newline at end of file
diff --git a/app/src/main/java/com/bnyro/translate/ui/views/AdditionalInfoComponent.kt b/app/src/main/java/com/bnyro/translate/ui/views/AdditionalInfoComponent.kt
index 90bbdfccd..a163be387 100644
--- a/app/src/main/java/com/bnyro/translate/ui/views/AdditionalInfoComponent.kt
+++ b/app/src/main/java/com/bnyro/translate/ui/views/AdditionalInfoComponent.kt
@@ -74,7 +74,7 @@ fun AdditionalInfoComponent(
AdditionalInfo(
title = stringResource(R.string.definition),
text = listOfNotNull(it.type, it.definition, it.example, it.synonym).joinToString(
- ", "
+ " • "
)
)
}