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 7b0e9584..3a430293 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
@@ -51,6 +51,8 @@ public class TranslateHelper {
et = MyTransL.translatorEngine.LIBRETRANSLATE;
} else if (translator.compareToIgnoreCase("LINGVA") == 0) {
et = MyTransL.translatorEngine.LINGVA;
+ } else if (translator.compareToIgnoreCase("MINT") == 0) {
+ et = MyTransL.translatorEngine.MINT;
} else {
et = MyTransL.translatorEngine.DEEPL;
}
@@ -68,7 +70,13 @@ public class TranslateHelper {
host = context.getString(R.string.SET_TRANSLATOR_HOST_LINGVA);
}
myTransL.setLingvaDomain(host);
- } else {
+ } else if (translator.compareToIgnoreCase("MINT") == 0) {
+ String host = sharedpreferences.getString(context.getString(R.string.SET_TRANSLATOR_DOMAIN_MINT), context.getString(R.string.SET_TRANSLATOR_HOST_MINT));
+ if (host == null || host.trim().isEmpty()) {
+ host = context.getString(R.string.SET_TRANSLATOR_HOST_MINT);
+ }
+ myTransL.setMintDomain(host);
+ }else {
String translatorVersion = sharedpreferences.getString(context.getString(R.string.SET_TRANSLATOR_VERSION), "PRO");
params.setPro(translatorVersion.equals("PRO"));
String apikey = sharedpreferences.getString(context.getString(R.string.SET_TRANSLATOR_API_KEY), null);
diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentTimelinesSettings.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentTimelinesSettings.java
index 0383e1f8..33d8cf14 100644
--- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentTimelinesSettings.java
+++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentTimelinesSettings.java
@@ -76,6 +76,13 @@ public class FragmentTimelinesSettings extends PreferenceFragmentCompat implemen
}
}
+ if (SET_TRANSLATOR != null && !SET_TRANSLATOR.getValue().equals("MINT")) {
+ if (SET_TRANSLATOR_DOMAIN != null) {
+ preferenceScreen.removePreferenceRecursively("SET_TRANSLATOR_DOMAIN_MINT");
+ }
+ }
+
+
SwitchPreferenceCompat SET_DISPLAY_BOOKMARK = findPreference(getString(R.string.SET_DISPLAY_BOOKMARK));
if (SET_DISPLAY_BOOKMARK != null) {
boolean checked = sharedpreferences.getBoolean(getString(R.string.SET_DISPLAY_BOOKMARK) + MainActivity.currentUserID + MainActivity.currentInstance, true);
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index aff9b602..15ee7630 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -857,6 +857,7 @@
- Fedilab
- Lingva
- DeepL
+ - Mint
- Free
@@ -867,6 +868,7 @@
- FEDILAB
- LINGVA
- DEEPL
+ - MINT
@@ -1176,8 +1178,11 @@
SET_POST_FORMAT
SET_COMPOSE_LOCAL_ONLY
+ translate.wmcloud.org
lingva.ml
SET_TRANSLATOR_DOMAIN
+ SET_TRANSLATOR_DOMAIN_MINT
+
SET_TRANSLATOR
SET_TRANSLATOR_VERSION
diff --git a/app/src/main/res/xml/pref_timelines.xml b/app/src/main/res/xml/pref_timelines.xml
index 4f47cb44..6309cb27 100644
--- a/app/src/main/res/xml/pref_timelines.xml
+++ b/app/src/main/res/xml/pref_timelines.xml
@@ -164,6 +164,13 @@
app:key="@string/SET_TRANSLATOR_DOMAIN"
app:title="@string/translator_domain"
app:useSimpleSummaryProvider="true" />
+
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("target_language", toLanguage);
+ params.put("content", contentToSend);
+ params.put("format", "text");
+ params.put("model", "nllb200-600M");
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
+ str_response = new Client().post(MyTransL.getMintUrl(), this.timeout, params);
}
} catch (IOException | NoSuchAlgorithmException | KeyManagementException err) {
this.e = new HttpsConnectionException(-1, err.getMessage());
@@ -177,6 +201,8 @@ public class TransAsync {
translate.parseLibreTranslateResult(result, listener);
} else if (this.te == MyTransL.translatorEngine.LINGVA) {
translate.parseLingvaResult(result, listener);
+ } else if (this.te == MyTransL.translatorEngine.MINT) {
+ translate.parseMintResult(result, listener);
}
//Obfuscation if asked
if (obfuscation) {
diff --git a/mytransl/src/main/java/com/github/stom79/mytransl/translate/Translate.java b/mytransl/src/main/java/com/github/stom79/mytransl/translate/Translate.java
index 22cd94c8..7c9af07b 100644
--- a/mytransl/src/main/java/com/github/stom79/mytransl/translate/Translate.java
+++ b/mytransl/src/main/java/com/github/stom79/mytransl/translate/Translate.java
@@ -360,6 +360,33 @@ public class Translate {
}
}
+
+ /***
+ * Method to parse result coming from the Mint
+ * @param response String - Response of the engine translator
+ * @param listener - Results Listener
+ */
+ public void parseMintResult(String response, Results listener) {
+ translate.setTranslatorEngine(MyTransL.translatorEngine.MINT);
+ try {
+ JSONObject translationJson = new JSONObject(response);
+ //Retrieves the translated content
+ String content;
+ try {
+ content = URLDecoder.decode(translationJson.getString("translation"), "utf-8");
+ } catch (UnsupportedEncodingException e) {
+ content = translationJson.getString("translation");
+ }
+ translate.setTranslatedContent(content);
+ //Retrieves the initial language
+ translate.setInitialLanguage(initialLanguage);
+ } catch (JSONException e1) {
+ e1.printStackTrace();
+ HttpsConnectionException httpsConnectionException = new HttpsConnectionException(-1, e1.getMessage());
+ listener.onFail(httpsConnectionException);
+ }
+ }
+
/***
* Method to parse result coming from the Deepl translator
* More about Deepl translate API - https://www.deepl.com/api-reference.html