diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/MediaActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/MediaActivity.java index 58547752..b5e85f0f 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/MediaActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/MediaActivity.java @@ -190,7 +190,7 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload binding.mediaDescription.setText(description); binding.translate.setOnClickListener(v -> { String descriptionToTranslate = attachments.get(mediaPosition - 1).description; - TranslateHelper.translate(MediaActivity.this, descriptionToTranslate, translated -> { + TranslateHelper.translate(MediaActivity.this, descriptionToTranslate, status.language, translated -> { if (translated != null) { attachments.get(mediaPosition - 1).translation = translated; binding.mediaDescriptionTranslated.setText(translated); @@ -239,7 +239,7 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload } binding.translate.setOnClickListener(v -> { String descriptionToTranslate = attachments.get(position).description; - TranslateHelper.translate(MediaActivity.this, descriptionToTranslate, translated -> { + TranslateHelper.translate(MediaActivity.this, descriptionToTranslate, status.language, translated -> { if (translated != null) { attachments.get(position).translation = translated; binding.mediaDescriptionTranslated.setText(translated); diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/TranslateHelper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/TranslateHelper.java index 3a430293..2f42edc7 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/TranslateHelper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/TranslateHelper.java @@ -38,7 +38,7 @@ import es.dmoral.toasty.Toasty; public class TranslateHelper { - public static void translate(Context context, String toTranslate, Translate callback) { + public static void translate(Context context, String toTranslate, String languageSource, Translate callback) { String statusToTranslate; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) statusToTranslate = Html.fromHtml(toTranslate, Html.FROM_HTML_MODE_LEGACY).toString(); @@ -61,7 +61,15 @@ public class TranslateHelper { Params params = new Params(); params.setSplit_sentences(false); params.setFormat(Params.fType.TEXT); - params.setSource_lang("auto"); + if(et != MyTransL.translatorEngine.MINT) { + params.setSource_lang("auto"); + } else { + if(languageSource != null && !languageSource.isEmpty()) { + params.setSource_lang(languageSource); + } else { + params.setSource_lang("en"); + } + } if (translator.compareToIgnoreCase("FEDILAB") == 0) { myTransL.setLibretranslateDomain("translate.fedilab.app"); } else if (translator.compareToIgnoreCase("LINGVA") == 0) { diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ReleaseNoteAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ReleaseNoteAdapter.java index 8334f842..7b9c4056 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ReleaseNoteAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ReleaseNoteAdapter.java @@ -74,7 +74,7 @@ public class ReleaseNoteAdapter extends RecyclerView.Adapter TranslateHelper.translate(context, note.note, translated -> { + holder.binding.translate.setOnClickListener(v -> TranslateHelper.translate(context, note.note, "en", translated -> { if (translated != null) { note.noteTranslated = translated; notifyItemChanged(holder.getBindingAdapterPosition()); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java index 2e9c335a..23d3db65 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java @@ -2765,7 +2765,7 @@ public class StatusAdapter extends RecyclerView.Adapter statusToTranslate = Html.fromHtml(statusToDeal.content).toString(); int countMorseChar = ComposeAdapter.countMorseChar(statusToTranslate); if (countMorseChar < 4) { - TranslateHelper.translate(context, statusToDeal.content, translated -> { + TranslateHelper.translate(context, statusToDeal.content, statusToDeal.language, translated -> { if (translated != null) { statusToDeal.translationShown = true; statusToDeal.translationContent = translated; diff --git a/mytransl/build.gradle b/mytransl/build.gradle index 8a4d7513..a1a7bdb6 100644 --- a/mytransl/build.gradle +++ b/mytransl/build.gradle @@ -29,6 +29,5 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.legacy:legacy-support-v4:1.0.0' - implementation("com.github.pemistahl:lingua:1.2.2") implementation "com.google.code.gson:gson:2.10.1" } diff --git a/mytransl/src/main/java/com/github/stom79/mytransl/async/TransAsync.java b/mytransl/src/main/java/com/github/stom79/mytransl/async/TransAsync.java index 5e2078fe..65b574a7 100644 --- a/mytransl/src/main/java/com/github/stom79/mytransl/async/TransAsync.java +++ b/mytransl/src/main/java/com/github/stom79/mytransl/async/TransAsync.java @@ -17,9 +17,6 @@ package com.github.stom79.mytransl.async; import android.os.Handler; import android.os.Looper; -import com.github.pemistahl.lingua.api.Language; -import com.github.pemistahl.lingua.api.LanguageDetector; -import com.github.pemistahl.lingua.api.LanguageDetectorBuilder; import com.github.stom79.mytransl.MyTransL; import com.github.stom79.mytransl.client.Client; import com.github.stom79.mytransl.client.HttpsConnectionException; @@ -35,7 +32,6 @@ import java.io.IOException; import java.net.URLEncoder; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; -import java.util.SortedMap; /** @@ -157,19 +153,10 @@ public class TransAsync { str_response = new Client().get(lingvaURL, this.timeout); } else if(te == MyTransL.translatorEngine.MINT) { JSONObject params = new JSONObject(); - LanguageDetector languageDetector = LanguageDetectorBuilder.fromAllLanguages().withMinimumRelativeDistance(0.25).build(); - SortedMap languages = languageDetector.computeLanguageConfidenceValues(contentToSend); - String fromLanguage = null; - if(!languages.isEmpty()) { - Language language = languages.firstKey(); - fromLanguage = language.getIsoCode639_1().name(); - } - if(fromLanguage == null) { - fromLanguage = "en"; - } + try { - params.put("source_language", fromLanguage.toLowerCase()); + params.put("source_language", this.params.getSource_lang()); params.put("target_language", toLanguage); params.put("content", contentToSend); params.put("format", "text");