Added experimental transliterate support

pull/214/head
M66B 1 year ago
parent a6ff7bd463
commit 8f5beaf615

@ -168,6 +168,10 @@ public class DeepL {
}
});
if (BuildConfig.DEBUG && TextHelper.canTransliterate())
languages.add(0, new Language(context.getString(R.string.title_advanced_notify_transliterate),
"transliterate", false, null, true, 0));
return languages;
} catch (Throwable ex) {
Log.e(ex);
@ -193,6 +197,13 @@ public class DeepL {
}
public static Translation translate(CharSequence text, boolean html, String target, boolean formality, Context context) throws IOException, JSONException {
if ("transliterate".equals(target)) {
Locale detected = TextHelper.detectLanguage(context, text.toString());
String transliterated = TextHelper.transliterate(context, text.toString());
String language = Locale.getDefault().toLanguageTag();
return new Translation(detected == null ? language : detected.toLanguageTag(), language, transliterated);
}
if (!ConnectionHelper.getNetworkState(context).isConnected())
throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
@ -367,6 +378,15 @@ public class DeepL {
public String detected_language;
public String target_language;
public CharSequence translated_text;
Translation() {
}
Translation(String detected, String target, CharSequence text) {
this.detected_language = detected;
this.target_language = target;
this.translated_text = text;
}
}
public static class FragmentDialogDeepL extends FragmentDialogBase {

@ -120,7 +120,7 @@ public class FragmentDialogTranslate extends FragmentDialogBase {
ssb.setSpan(new ForegroundColorSpan(textColorPrimary), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
Locale source = Locale.forLanguageTag(translation.detected_language);
Locale target = Locale.forLanguageTag(args.getString("target"));
Locale target = Locale.forLanguageTag(translation.target_language);
String lang = "[" + source.getDisplayLanguage(target) + "]\n\n";
ssb.insert(0, lang);
@ -292,7 +292,7 @@ public class FragmentDialogTranslate extends FragmentDialogBase {
ssb.setSpan(new ForegroundColorSpan(textColorPrimary), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
Locale source = Locale.forLanguageTag(translation.detected_language);
Locale target = Locale.forLanguageTag(args.getString("target"));
Locale target = Locale.forLanguageTag(translation.target_language);
String lang = "[" + source.getDisplayLanguage(target) + "] ";
ssb.insert(start, lang);

Loading…
Cancel
Save