From 093b576e0d97d13b6aa71ac5d8ca1e80d996ee39 Mon Sep 17 00:00:00 2001 From: Georg Lukas Date: Tue, 30 Jul 2019 15:33:38 +0200 Subject: [PATCH] Errors: language selection for error description --- .../smack/packet/AbstractError.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/packet/AbstractError.java b/smack-core/src/main/java/org/jivesoftware/smack/packet/AbstractError.java index d6a0d56a2..5a4621bb6 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/packet/AbstractError.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/packet/AbstractError.java @@ -66,15 +66,23 @@ public class AbstractError { * @return the descriptive text or null. */ public String getDescriptiveText() { - String defaultLocale = Locale.getDefault().getLanguage(); - String descriptiveText = getDescriptiveText(defaultLocale); - if (descriptiveText == null) { - descriptiveText = getDescriptiveText("en"); - if (descriptiveText == null) { - descriptiveText = getDescriptiveText(""); - } + if (descriptiveTexts.isEmpty()) + return null; + // attempt to obtain the text in the user's locale, the English text, or the "" default + Locale l = Locale.getDefault(); + String[] tags = new String[] { + l.getLanguage() + "-" + l.getCountry() + "-" + l.getVariant(), + l.getLanguage() + "-" + l.getCountry(), + l.getLanguage(), + "en", + "" + }; + for (String tag : tags) { + String descriptiveText = getDescriptiveText(tag); + if (descriptiveText != null) + return descriptiveText; } - return descriptiveText; + return descriptiveTexts.values().iterator().next(); } /**