Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

adjust servlet RequestHeader.getLocale init jvm defaultLocale matching UI language

reger2a4d826d9e25
diff --git a/source/net/yacy/cora/protocol/RequestHeader.java b/source/net/yacy/cora/protocol/RequestHeader.java
index 6c13cc482..05a6aef72 100644
--- a/source/net/yacy/cora/protocol/RequestHeader.java
+++ b/source/net/yacy/cora/protocol/RequestHeader.java
@@ -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
diff --git a/source/net/yacy/search/Switchboard.java b/source/net/yacy/search/Switchboard.java
index dafd120c9..922dfd699 100644
--- a/source/net/yacy/search/Switchboard.java
+++ b/source/net/yacy/search/Switchboard.java
@@ -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);
}
}
}