Check internet connection on translate

This commit is contained in:
M66B 2022-03-21 15:38:10 +01:00
parent 401ded742f
commit c6319a0974
1 changed files with 3 additions and 0 deletions

View File

@ -197,6 +197,9 @@ public class DeepL {
}
public static Translation translate(String text, String target, boolean formality, Context context) throws IOException, JSONException {
if (!ConnectionHelper.getNetworkState(context).isConnected())
throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
// https://www.deepl.com/docs-api/translating-text/request/
String request =
"text=" + URLEncoder.encode(text, StandardCharsets.UTF_8.name()) +