diff --git a/app/src/main/java/eu/faircode/email/DeepL.java b/app/src/main/java/eu/faircode/email/DeepL.java
index e7622bef2f..683db6af6e 100644
--- a/app/src/main/java/eu/faircode/email/DeepL.java
+++ b/app/src/main/java/eu/faircode/email/DeepL.java
@@ -33,6 +33,7 @@ import android.text.style.RelativeSizeSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
+import android.widget.CompoundButton;
import android.widget.ImageButton;
import android.widget.TextView;
@@ -349,6 +350,7 @@ public class DeepL {
String key = prefs.getString("deepl_key", null);
boolean formal = prefs.getBoolean("deepl_formal", true);
boolean small = prefs.getBoolean("deepl_small", false);
+ boolean replace = prefs.getBoolean("deepl_replace", false);
boolean html = prefs.getBoolean("deepl_html", false);
int subscription = prefs.getInt("deepl_subscription", BuildConfig.DEBUG ? 17 : 0);
@@ -358,6 +360,7 @@ public class DeepL {
final CheckBox cbFormal = view.findViewById(R.id.cbFormal);
final TextView tvFormal = view.findViewById(R.id.tvFormal);
final CheckBox cbSmall = view.findViewById(R.id.cbSmall);
+ final CheckBox cbReplace = view.findViewById(R.id.cbReplace);
final CheckBox cbHtml = view.findViewById(R.id.cbHtml);
final TextView tvUsage = view.findViewById(R.id.tvUsage);
final TextView tvPrivacy = view.findViewById(R.id.tvPrivacy);
@@ -369,6 +372,13 @@ public class DeepL {
}
});
+ cbSmall.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ cbReplace.setEnabled(!isChecked);
+ }
+ });
+
tvUsage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -399,6 +409,8 @@ public class DeepL {
}
cbSmall.setChecked(small);
+ cbReplace.setChecked(replace);
+ cbReplace.setEnabled(!small);
cbHtml.setChecked(html);
tvUsage.setVisibility(View.GONE);
@@ -461,6 +473,7 @@ public class DeepL {
editor.putString("deepl_key", key);
editor.putBoolean("deepl_formal", cbFormal.isChecked());
editor.putBoolean("deepl_small", cbSmall.isChecked());
+ editor.putBoolean("deepl_replace", cbReplace.isChecked());
editor.putBoolean("deepl_html", cbHtml.isChecked());
editor.apply();
}
diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java
index 9c95cd660d..47da8cccca 100644
--- a/app/src/main/java/eu/faircode/email/FragmentCompose.java
+++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java
@@ -2751,6 +2751,8 @@ public class FragmentCompose extends FragmentBase {
return;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ boolean small = prefs.getBoolean("deepl_small", false);
+ boolean replace = prefs.getBoolean("deepl_replace", false);
// Insert translated text
/*
@@ -2773,22 +2775,28 @@ public class FragmentCompose extends FragmentBase {
at android.text.SpannableStringBuilder.insert(SpannableStringBuilder.java:226)
at android.text.SpannableStringBuilder.insert(SpannableStringBuilder.java:38)
*/
- int len = 2 + translation.translated_text.length();
- edit.insert(paragraph.second, translation.translated_text);
- edit.insert(paragraph.second, "\n\n");
- StyleHelper.markAsInserted(edit, paragraph.second, paragraph.second + len);
+ int len = translation.translated_text.length();
+ edit.insert(paragraph.second, translation.translated_text);
+
+ if (!replace) {
+ edit.insert(paragraph.second, "\n\n");
+ len += 2;
+ }
+
+ StyleHelper.markAsInserted(edit, paragraph.second, paragraph.second + len);
etBody.setSelection(paragraph.second + len);
- boolean small = prefs.getBoolean("deepl_small", false);
if (small) {
RelativeSizeSpan[] spans = edit.getSpans(
paragraph.first, paragraph.second, RelativeSizeSpan.class);
for (RelativeSizeSpan span : spans)
edit.removeSpan(span);
- edit.setSpan(new RelativeSizeSpan(BuildConfig.DEBUG ? HtmlHelper.FONT_XSMALL : HtmlHelper.FONT_SMALL),
+ edit.setSpan(new RelativeSizeSpan(HtmlHelper.FONT_SMALL),
paragraph.first, paragraph.second,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ } else if (replace) {
+ edit.delete(paragraph.first, paragraph.second);
}
// Updated frequency
diff --git a/app/src/main/res/layout/dialog_deepl.xml b/app/src/main/res/layout/dialog_deepl.xml
index 67ee1b8147..fb868467ad 100644
--- a/app/src/main/res/layout/dialog_deepl.xml
+++ b/app/src/main/res/layout/dialog_deepl.xml
@@ -89,6 +89,16 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvFormal" />
+
+
+ app:layout_constraintTop_toBottomOf="@id/cbReplace" />
Translating …
Use formal form
Use a small font for the source text
+ Replace source text by translated text
Preserve formatting
This will consume more characters
Usage: %1$s / %2$s (%3$d %%)