From 7ff276cb828fea9c255e9323e34f8fd39faeb7e9 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 29 Jun 2021 12:01:31 +0200 Subject: [PATCH] Improved DeepL current language selection --- FAQ.md | 2 ++ app/src/main/java/eu/faircode/email/DeepL.java | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/FAQ.md b/FAQ.md index 07d6f0cca1..414efbeba9 100644 --- a/FAQ.md +++ b/FAQ.md @@ -3708,11 +3708,13 @@ Unfortunately, it is not possible to hide messages on the email server too. **(167) How can I use DeepL?** +1. Check if [DeepL](https://www.deepl.com/) supports your language 1. Enable DeepL support in the miscellaneous settings 1. [Subscribe to](https://www.deepl.com/pro#developer) the DeepL API Free or Pro plan (credit card required) 1. [Copy](https://www.deepl.com/pro-account/plan) the authentication key 1. In the message composer tap on the faint translate button (文A), select *Configure* and paste the key + You might want to read the [privacy policy](https://www.deepl.com/privacy/) of DeepL. This feature requires an internet connection and is not available in the Play store version. diff --git a/app/src/main/java/eu/faircode/email/DeepL.java b/app/src/main/java/eu/faircode/email/DeepL.java index 2c145440a0..c9eabf5eba 100644 --- a/app/src/main/java/eu/faircode/email/DeepL.java +++ b/app/src/main/java/eu/faircode/email/DeepL.java @@ -140,11 +140,25 @@ public class DeepL { 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(locale.toLanguageTag()) || - language.equalsIgnoreCase(locale.getLanguage())) { + if (language.equalsIgnoreCase(lang)) { return language; } }