Merge pull request #330 from ge0rg/errlang

Errors: language selection for error description
This commit is contained in:
Florian Schmaus 2019-09-16 17:42:45 +02:00 committed by GitHub
commit 65b6a7bfa2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 8 deletions

View File

@ -66,15 +66,23 @@ public class AbstractError {
* @return the descriptive text or null. * @return the descriptive text or null.
*/ */
public String getDescriptiveText() { public String getDescriptiveText() {
String defaultLocale = Locale.getDefault().getLanguage(); if (descriptiveTexts.isEmpty())
String descriptiveText = getDescriptiveText(defaultLocale); return null;
if (descriptiveText == null) { // attempt to obtain the text in the user's locale, the English text, or the "" default
descriptiveText = getDescriptiveText("en"); Locale l = Locale.getDefault();
if (descriptiveText == null) { String[] tags = new String[] {
descriptiveText = getDescriptiveText(""); 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();
} }
/** /**