This commit is contained in:
Thomas 2023-02-14 11:02:04 +01:00
parent 4eb4c6eea5
commit 4b8563fe7e
6 changed files with 30 additions and 3 deletions

View file

@ -63,7 +63,11 @@ public class TranslateHelper {
if (translator.compareToIgnoreCase("FEDILAB") == 0) { if (translator.compareToIgnoreCase("FEDILAB") == 0) {
myTransL.setLibretranslateDomain("translate.fedilab.app"); myTransL.setLibretranslateDomain("translate.fedilab.app");
} else if (translator.compareToIgnoreCase("LINGVA") == 0) { } else if (translator.compareToIgnoreCase("LINGVA") == 0) {
myTransL.setLibretranslateDomain("lingva.ml"); String host = sharedpreferences.getString(context.getString(R.string.SET_TRANSLATOR_DOMAIN), context.getString(R.string.SET_TRANSLATOR_HOST_LINGVA));
if (host == null || host.trim().isEmpty()) {
host = context.getString(R.string.SET_TRANSLATOR_HOST_LINGVA);
}
myTransL.setLingvaDomain(host);
} else { } else {
String translatorVersion = sharedpreferences.getString(context.getString(R.string.SET_TRANSLATOR_VERSION), "PRO"); String translatorVersion = sharedpreferences.getString(context.getString(R.string.SET_TRANSLATOR_VERSION), "PRO");
params.setPro(translatorVersion.equals("PRO")); params.setPro(translatorVersion.equals("PRO"));

View file

@ -47,7 +47,8 @@ public class FragmentTimelinesSettings extends PreferenceFragmentCompat implemen
ListPreference SET_TRANSLATOR_VERSION = findPreference(getString(R.string.SET_TRANSLATOR_VERSION)); ListPreference SET_TRANSLATOR_VERSION = findPreference(getString(R.string.SET_TRANSLATOR_VERSION));
EditTextPreference SET_TRANSLATOR_API_KEY = findPreference(getString(R.string.SET_TRANSLATOR_API_KEY)); EditTextPreference SET_TRANSLATOR_API_KEY = findPreference(getString(R.string.SET_TRANSLATOR_API_KEY));
if (SET_TRANSLATOR != null && SET_TRANSLATOR.getValue().equals("FEDILAB")) { EditTextPreference SET_TRANSLATOR_DOMAIN = findPreference(getString(R.string.SET_TRANSLATOR_DOMAIN));
if (SET_TRANSLATOR != null && !SET_TRANSLATOR.getValue().equals("DEEPL")) {
if (SET_TRANSLATOR_API_KEY != null) { if (SET_TRANSLATOR_API_KEY != null) {
preferenceScreen.removePreferenceRecursively("SET_TRANSLATOR_API_KEY"); preferenceScreen.removePreferenceRecursively("SET_TRANSLATOR_API_KEY");
} }
@ -55,6 +56,11 @@ public class FragmentTimelinesSettings extends PreferenceFragmentCompat implemen
preferenceScreen.removePreferenceRecursively("SET_TRANSLATOR_VERSION"); preferenceScreen.removePreferenceRecursively("SET_TRANSLATOR_VERSION");
} }
} }
if (SET_TRANSLATOR != null && !SET_TRANSLATOR.getValue().equals("LINGVA")) {
if (SET_TRANSLATOR_DOMAIN != null) {
preferenceScreen.removePreferenceRecursively("SET_TRANSLATOR_DOMAIN");
}
}
SwitchPreferenceCompat SET_DISPLAY_BOOKMARK = findPreference(getString(R.string.SET_DISPLAY_BOOKMARK)); SwitchPreferenceCompat SET_DISPLAY_BOOKMARK = findPreference(getString(R.string.SET_DISPLAY_BOOKMARK));
if (SET_DISPLAY_BOOKMARK != null) { if (SET_DISPLAY_BOOKMARK != null) {
boolean checked = sharedpreferences.getBoolean(getString(R.string.SET_DISPLAY_BOOKMARK) + MainActivity.currentUserID + MainActivity.currentInstance, true); boolean checked = sharedpreferences.getBoolean(getString(R.string.SET_DISPLAY_BOOKMARK) + MainActivity.currentUserID + MainActivity.currentInstance, true);

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="translator_domain">Translator domain</string>
</resources>

View file

@ -796,6 +796,7 @@
<string-array name="set_translator_values" translatable="false"> <string-array name="set_translator_values" translatable="false">
<item>Fedilab</item> <item>Fedilab</item>
<item>Lingva</item>
<item>DeepL</item> <item>DeepL</item>
</string-array> </string-array>
<string-array name="set_translator_version_values"> <string-array name="set_translator_version_values">
@ -805,6 +806,7 @@
<string-array name="SET_TRANSLATOR_VALUES" translatable="false"> <string-array name="SET_TRANSLATOR_VALUES" translatable="false">
<item>FEDILAB</item> <item>FEDILAB</item>
<item>LINGVA</item>
<item>DEEPL</item> <item>DEEPL</item>
</string-array> </string-array>
@ -1097,6 +1099,8 @@
<string name="SET_POST_FORMAT" translatable="false">SET_POST_FORMAT</string> <string name="SET_POST_FORMAT" translatable="false">SET_POST_FORMAT</string>
<string name="SET_COMPOSE_LOCAL_ONLY" translatable="false">SET_COMPOSE_LOCAL_ONLY</string> <string name="SET_COMPOSE_LOCAL_ONLY" translatable="false">SET_COMPOSE_LOCAL_ONLY</string>
<string name="SET_TRANSLATOR_HOST_LINGVA" translatable="false">lingva.ml</string>
<string name="SET_TRANSLATOR_DOMAIN" translatable="false">SET_TRANSLATOR_DOMAIN</string>
<string name="SET_TRANSLATOR" translatable="false">SET_TRANSLATOR</string> <string name="SET_TRANSLATOR" translatable="false">SET_TRANSLATOR</string>
<string name="SET_TRANSLATOR_VERSION" translatable="false">SET_TRANSLATOR_VERSION</string> <string name="SET_TRANSLATOR_VERSION" translatable="false">SET_TRANSLATOR_VERSION</string>

View file

@ -93,6 +93,13 @@
app:key="@string/SET_TRANSLATOR_API_KEY" app:key="@string/SET_TRANSLATOR_API_KEY"
app:title="@string/api_key" app:title="@string/api_key"
app:useSimpleSummaryProvider="true" /> app:useSimpleSummaryProvider="true" />
<EditTextPreference
app:defaultValue="lingva.ml"
app:dependency="@string/SET_TRANSLATOR"
app:iconSpaceReserved="false"
app:key="@string/SET_TRANSLATOR_DOMAIN"
app:title="@string/translator_domain"
app:useSimpleSummaryProvider="true" />
<ListPreference <ListPreference
app:defaultValue="PRO" app:defaultValue="PRO"
app:dialogTitle="@string/version" app:dialogTitle="@string/version"

View file

@ -29,6 +29,7 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
@ -148,7 +149,8 @@ public class TransAsync {
str_response = new Client().post(MyTransL.getLibreTranslateUrl(), this.timeout, params); str_response = new Client().post(MyTransL.getLibreTranslateUrl(), this.timeout, params);
} else if (te == MyTransL.translatorEngine.LINGVA) { } else if (te == MyTransL.translatorEngine.LINGVA) {
String key = MyTransL.getInstance(te).getLibreTranslateAPIKey(); String key = MyTransL.getInstance(te).getLibreTranslateAPIKey();
String lingvaURL = MyTransL.getLingvaUrl() + this.params.getSource_lang() + "/" + toLanguage + "/" + contentToSend; String contentToSendEncoded = URLEncoder.encode(contentToSend, "UTF-8");
String lingvaURL = MyTransL.getLingvaUrl() + this.params.getSource_lang() + "/" + toLanguage + "/" + contentToSendEncoded;
str_response = new Client().get(lingvaURL, this.timeout); str_response = new Client().get(lingvaURL, this.timeout);
} }
} catch (IOException | NoSuchAlgorithmException | KeyManagementException err) { } catch (IOException | NoSuchAlgorithmException | KeyManagementException err) {