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 7f91a364..7b0e9584 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 @@ -72,8 +72,15 @@ public class TranslateHelper { 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); - if (apikey != null) { + if (apikey != null && !apikey.trim().isEmpty()) { myTransL.setDeeplAPIKey(apikey.trim()); + } else { //Issue with API key (empty or null) + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putString(context.getString(R.string.SET_TRANSLATOR), "FEDILAB"); + editor.commit(); + et = MyTransL.translatorEngine.LIBRETRANSLATE; + myTransL.setTranslator(et); + myTransL.setLibretranslateDomain("translate.fedilab.app"); } } diff --git a/mytransl/src/main/java/com/github/stom79/mytransl/MyTransL.java b/mytransl/src/main/java/com/github/stom79/mytransl/MyTransL.java index e2c997ec..549ee181 100644 --- a/mytransl/src/main/java/com/github/stom79/mytransl/MyTransL.java +++ b/mytransl/src/main/java/com/github/stom79/mytransl/MyTransL.java @@ -29,7 +29,7 @@ public class MyTransL { private static MyTransL myTransL; private static String libretranslateDomain; private static String lingvaDomain; - private final translatorEngine te; + private translatorEngine te; private String yandexAPIKey, deeplAPIKey, systranAPIKey, libreTranslateAPIKey, lingvaAPIKey; private int timeout = 30; private boolean obfuscation = false; @@ -38,6 +38,10 @@ public class MyTransL { this.te = te; } + public void setTranslator(translatorEngine te) { + this.te = te; + } + public static synchronized MyTransL getInstance(translatorEngine te) { if (myTransL == null) myTransL = new MyTransL(te);