Select DeepL target language

This commit is contained in:
M66B
2021-06-29 16:09:28 +02:00
parent daf4aa4511
commit 4eee5f9e72
3 changed files with 67 additions and 41 deletions

View File

@@ -135,40 +135,6 @@ public class DeepL {
}
}
public static String getCurrentLanguage(Context context) {
try {
ensureLanguages(context);
Locale locale = Locale.getDefault();
String tag = locale.toLanguageTag(); // en-US
String lang = locale.getLanguage(); // en
if ("en".equalsIgnoreCase(lang))
if ("EN-GB".equalsIgnoreCase(tag) || "EN-US".equalsIgnoreCase(tag))
lang = tag;
else
lang = "EN-US";
if ("pt".equalsIgnoreCase(lang))
if ("PT-BR".equalsIgnoreCase(tag) || "PT-PT".equalsIgnoreCase(tag))
lang = tag;
else
lang = "PT-PT";
for (int i = 0; i < jlanguages.length(); i++) {
JSONObject jlanguage = jlanguages.getJSONObject(i);
String language = jlanguage.getString("language");
if (language.equalsIgnoreCase(lang)) {
return language;
}
}
} catch (Throwable ex) {
Log.e(ex);
}
return null;
}
private static void ensureLanguages(Context context) throws IOException, JSONException {
if (jlanguages != null)
return;
@@ -321,6 +287,11 @@ public class DeepL {
this.target = target;
this.icon = icon;
}
@Override
public String toString() {
return name;
}
}
public static class Translation {