adjust servlet RequestHeader.getLocale

init jvm defaultLocale matching UI language
pull/93/head
reger 8 years ago
parent 200e7a7292
commit 2a4d826d9e

@ -703,9 +703,11 @@ public class RequestHeader extends HeaderFramework implements HttpServletRequest
public Locale getLocale() {
if (this._request != null) {
return _request.getLocale();
} else {
throw new UnsupportedOperationException("Not supported yet.");
} else if (super.containsKey(HeaderFramework.ACCEPT_LANGUAGE)) {
final String lng = super.get(HeaderFramework.ACCEPT_LANGUAGE);
return new Locale(lng);
}
return Locale.getDefault(); // to avoid dependency on Switchboard just use system default
}
@Override

@ -64,6 +64,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@ -666,6 +667,14 @@ public final class Switchboard extends serverSwitch {
ListManager.listsPath = blacklistsPath;
ListManager.reloadBlacklists();
// Set jvm default locale to match UI language (
String lng = this.getConfig("locale.language", "en");
if (!"browser".equals(lng) && !"default".equals(lng)) {
Locale.setDefault(new Locale(lng));
} else {
lng = "en"; // default = English
}
// load badwords (to filter the topwords)
if ( badwords == null || badwords.isEmpty() ) {
File badwordsFile = new File(appPath, "DATA/SETTINGS/" + SwitchboardConstants.LIST_BADWORDS_DEFAULT);
@ -689,8 +698,7 @@ public final class Switchboard extends serverSwitch {
}
stopwords = SetTools.loadList(stopwordsFile, NaturalOrder.naturalComparator);
// append locale language stopwords using setting of interface language (file yacy.stopwords.xx)
String lng = this.getConfig("locale.language", "en");
if ("default".equals(lng)) lng="en"; // english is stored as default (needed for locale html file overlay)
// english is stored as default (needed for locale html file overlay)
File stopwordsFilelocale = new File (dataPath, "DATA/SETTINGS/"+stopwordsFile.getName()+"."+lng);
if (!stopwordsFilelocale.exists()) stopwordsFilelocale = new File (appPath, "defaults/"+stopwordsFile.getName()+"."+lng);
if (stopwordsFilelocale.exists()) {
@ -3420,7 +3428,7 @@ public final class Switchboard extends serverSwitch {
}
if (s != null) {
Switchboard.this.log.info("addToCrawler: failed to add " + url.toNormalform(true) + ": " + s);
this.log.info("addToCrawler: failed to add " + url.toNormalform(true) + ": " + s);
}
}
}

Loading…
Cancel
Save