Localize reply header based on detected language

pull/178/head
M66B 5 years ago
parent af0e83d03b
commit 538525440c

@ -159,6 +159,7 @@ import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Properties; import java.util.Properties;
@ -3099,7 +3100,7 @@ public class FragmentCompose extends FragmentBase {
if (prefix_once) if (prefix_once)
for (String re : Helper.getStrings(context, ref.language, R.string.title_subject_reply, "")) for (String re : Helper.getStrings(context, ref.language, R.string.title_subject_reply, ""))
subject = unprefix(subject, re); subject = unprefix(subject, re);
data.draft.subject = context.getString(R.string.title_subject_reply, subject); data.draft.subject = Helper.getString(context, ref.language, R.string.title_subject_reply, subject);
String t = args.getString("text"); String t = args.getString("text");
if (t != null) { if (t != null) {
@ -3116,7 +3117,7 @@ public class FragmentCompose extends FragmentBase {
if (prefix_once) if (prefix_once)
for (String fwd : Helper.getStrings(context, ref.language, R.string.title_subject_forward, "")) for (String fwd : Helper.getStrings(context, ref.language, R.string.title_subject_forward, ""))
subject = unprefix(subject, fwd); subject = unprefix(subject, fwd);
data.draft.subject = context.getString(R.string.title_subject_forward, subject); data.draft.subject = Helper.getString(context, ref.language, R.string.title_subject_forward, subject);
} else if ("editasnew".equals(action)) { } else if ("editasnew".equals(action)) {
data.draft.subject = ref.subject; data.draft.subject = ref.subject;
if (ref.content) { if (ref.content) {
@ -3131,7 +3132,7 @@ public class FragmentCompose extends FragmentBase {
} else if ("receipt".equals(action)) { } else if ("receipt".equals(action)) {
data.draft.subject = context.getString(R.string.title_receipt_subject, subject); data.draft.subject = context.getString(R.string.title_receipt_subject, subject);
for (String text : Helper.getStrings(context, R.string.title_receipt_text)) { for (String text : Helper.getStrings(context, ref.language, R.string.title_receipt_text)) {
Element p = document.createElement("p"); Element p = document.createElement("p");
p.text(text); p.text(text);
document.body().appendChild(p); document.body().appendChild(p);
@ -3165,42 +3166,52 @@ public class FragmentCompose extends FragmentBase {
Element reply = document.createElement("div"); Element reply = document.createElement("div");
reply.attr("fairemail", "reference"); reply.attr("fairemail", "reference");
boolean language_detection = prefs.getBoolean("language_detection", false);
String language = (language_detection ? ref.language : null);
DateFormat DF;
if (language == null)
DF = Helper.getDateTimeInstance(context);
else
DF = SimpleDateFormat.getDateTimeInstance(
SimpleDateFormat.MEDIUM, SimpleDateFormat.MEDIUM,
new Locale(language));
// Build reply header // Build reply header
Element p = document.createElement("p"); Element p = document.createElement("p");
DateFormat DF = Helper.getDateTimeInstance(context);
boolean extended_reply = prefs.getBoolean("extended_reply", false); boolean extended_reply = prefs.getBoolean("extended_reply", false);
if (extended_reply) { if (extended_reply) {
if (ref.from != null && ref.from.length > 0) { if (ref.from != null && ref.from.length > 0) {
Element strong = document.createElement("strong"); Element strong = document.createElement("strong");
strong.text(context.getString(R.string.title_from) + " "); strong.text(Helper.getString(context, language, R.string.title_from) + " ");
p.appendChild(strong); p.appendChild(strong);
p.appendText(MessageHelper.formatAddresses(ref.from)); p.appendText(MessageHelper.formatAddresses(ref.from));
p.appendElement("br"); p.appendElement("br");
} }
if (ref.to != null && ref.to.length > 0) { if (ref.to != null && ref.to.length > 0) {
Element strong = document.createElement("strong"); Element strong = document.createElement("strong");
strong.text(context.getString(R.string.title_to) + " "); strong.text(Helper.getString(context, language, R.string.title_to) + " ");
p.appendChild(strong); p.appendChild(strong);
p.appendText(MessageHelper.formatAddresses(ref.to)); p.appendText(MessageHelper.formatAddresses(ref.to));
p.appendElement("br"); p.appendElement("br");
} }
if (ref.cc != null && ref.cc.length > 0) { if (ref.cc != null && ref.cc.length > 0) {
Element strong = document.createElement("strong"); Element strong = document.createElement("strong");
strong.text(context.getString(R.string.title_cc) + " "); strong.text(Helper.getString(context, language, R.string.title_cc) + " ");
p.appendChild(strong); p.appendChild(strong);
p.appendText(MessageHelper.formatAddresses(ref.cc)); p.appendText(MessageHelper.formatAddresses(ref.cc));
p.appendElement("br"); p.appendElement("br");
} }
{ {
Element strong = document.createElement("strong"); Element strong = document.createElement("strong");
strong.text(context.getString(R.string.title_received) + " "); strong.text(Helper.getString(context, language, R.string.title_received) + " ");
p.appendChild(strong); p.appendChild(strong);
p.appendText(DF.format(ref.received)); p.appendText(DF.format(ref.received));
p.appendElement("br"); p.appendElement("br");
} }
{ {
Element strong = document.createElement("strong"); Element strong = document.createElement("strong");
strong.text(context.getString(R.string.title_subject) + " "); strong.text(Helper.getString(context, language, R.string.title_subject) + " ");
p.appendChild(strong); p.appendChild(strong);
p.appendText(ref.subject == null ? "" : ref.subject); p.appendText(ref.subject == null ? "" : ref.subject);
p.appendElement("br"); p.appendElement("br");

@ -54,6 +54,7 @@ public class FragmentOptions extends FragmentBase {
"contrast", "monospaced", "text_color", "text_size", "contrast", "monospaced", "text_color", "text_size",
"inline_images", "collapse_quotes", "seekbar", "actionbar", "actionbar_color", "navbar_colorize", "inline_images", "collapse_quotes", "seekbar", "actionbar", "actionbar_color", "navbar_colorize",
"autoscroll", "swipenav", "autoexpand", "autoclose", "onclose", "autoscroll", "swipenav", "autoexpand", "autoclose", "onclose",
"language_detection",
"quick_filter", "quick_scroll", "quick_filter", "quick_scroll",
"experiments", "debug", "experiments", "debug",
"biometrics" "biometrics"

@ -752,6 +752,16 @@ public class Helper {
} }
} }
static String getString(Context context, String language, int resid, Object... formatArgs) {
if (language == null)
return context.getString(resid, formatArgs);
Configuration configuration = new Configuration(context.getResources().getConfiguration());
configuration.setLocale(new Locale(language));
Resources res = context.createConfigurationContext(configuration).getResources();
return res.getString(resid, formatArgs);
}
static String[] getStrings(Context context, int resid, Object... formatArgs) { static String[] getStrings(Context context, int resid, Object... formatArgs) {
return getStrings(context, null, resid, formatArgs); return getStrings(context, null, resid, formatArgs);
} }

Loading…
Cancel
Save