summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-04-28 10:47:08 -0600
committerJames Moger <james.moger@gitblit.com>2014-04-28 10:47:08 -0600
commitd8654bdf5c5e0e062a683b40ba826f9638e25d41 (patch)
treed8fcac0fbf1604f28f99f00e86ad05b247fc39b9 /src
parent175f34a07622ba2bf70642656e94ee342280859f (diff)
parenta8100bb4d3aa64e254e92e29130e8fd9bd4e0dd2 (diff)
downloadgitblit-d8654bdf5c5e0e062a683b40ba826f9638e25d41.tar.gz
gitblit-d8654bdf5c5e0e062a683b40ba826f9638e25d41.zip
Merged #51 "Can not force default locale to English or to a locale with a country code"
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/gitblit/manager/GitblitManager.java6
-rw-r--r--src/main/java/com/gitblit/manager/IRuntimeManager.java9
-rw-r--r--src/main/java/com/gitblit/manager/RuntimeManager.java19
-rw-r--r--src/main/java/com/gitblit/models/UserPreferences.java6
-rw-r--r--src/main/java/com/gitblit/wicket/GitBlitWebApp.java7
-rw-r--r--src/test/java/com/gitblit/tests/mock/MockRuntimeManager.java6
6 files changed, 49 insertions, 4 deletions
diff --git a/src/main/java/com/gitblit/manager/GitblitManager.java b/src/main/java/com/gitblit/manager/GitblitManager.java
index 790445a7..5b16ef66 100644
--- a/src/main/java/com/gitblit/manager/GitblitManager.java
+++ b/src/main/java/com/gitblit/manager/GitblitManager.java
@@ -27,6 +27,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
@@ -606,6 +607,11 @@ public class GitblitManager implements IGitblit {
}
@Override
+ public Locale getLocale() {
+ return runtimeManager.getLocale();
+ }
+
+ @Override
public boolean isDebugMode() {
return runtimeManager.isDebugMode();
}
diff --git a/src/main/java/com/gitblit/manager/IRuntimeManager.java b/src/main/java/com/gitblit/manager/IRuntimeManager.java
index acd3a576..29e7368f 100644
--- a/src/main/java/com/gitblit/manager/IRuntimeManager.java
+++ b/src/main/java/com/gitblit/manager/IRuntimeManager.java
@@ -17,6 +17,7 @@ package com.gitblit.manager;
import java.io.File;
import java.util.Date;
+import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
@@ -39,6 +40,14 @@ public interface IRuntimeManager extends IManager {
TimeZone getTimezone();
/**
+ * Returns the fixed locale for clients, or null if clients may choose their locale
+ *
+ * @return a fixed locale or null if clients are allowed to specify locale preference
+ * @since 1.5.1
+ */
+ Locale getLocale();
+
+ /**
* Determine if this Gitblit instance is actively serving git repositories
* or if it is merely a repository viewer.
*
diff --git a/src/main/java/com/gitblit/manager/RuntimeManager.java b/src/main/java/com/gitblit/manager/RuntimeManager.java
index 9805701b..52f4d67b 100644
--- a/src/main/java/com/gitblit/manager/RuntimeManager.java
+++ b/src/main/java/com/gitblit/manager/RuntimeManager.java
@@ -18,6 +18,7 @@ package com.gitblit.manager;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
@@ -63,6 +64,8 @@ public class RuntimeManager implements IRuntimeManager {
logger.info("Settings : " + settings.toString());
logTimezone("JVM timezone: ", TimeZone.getDefault());
logTimezone("App timezone: ", getTimezone());
+ logger.info("JVM locale : " + Locale.getDefault());
+ logger.info("App locale : " + (getLocale() == null ? "<client>" : getLocale()));
return this;
}
@@ -146,6 +149,22 @@ public class RuntimeManager implements IRuntimeManager {
logger.info("{}{} ({})", new Object [] { type, zone.getID(), offset });
}
+ @Override
+ public Locale getLocale() {
+ String lc = settings.getString(Keys.web.forceDefaultLocale, null);
+ if (!StringUtils.isEmpty(lc)) {
+ int underscore = lc.indexOf('_');
+ if (underscore > 0) {
+ String lang = lc.substring(0, underscore);
+ String cc = lc.substring(underscore + 1);
+ return new Locale(lang, cc);
+ } else {
+ return new Locale(lc);
+ }
+ }
+ return null;
+ }
+
/**
* Is Gitblit running in debug mode?
*
diff --git a/src/main/java/com/gitblit/models/UserPreferences.java b/src/main/java/com/gitblit/models/UserPreferences.java
index baab0719..44e44933 100644
--- a/src/main/java/com/gitblit/models/UserPreferences.java
+++ b/src/main/java/com/gitblit/models/UserPreferences.java
@@ -49,6 +49,12 @@ public class UserPreferences implements Serializable {
if (StringUtils.isEmpty(locale)) {
return null;
}
+ int underscore = locale.indexOf('_');
+ if (underscore > 0) {
+ String lang = locale.substring(0, underscore);
+ String cc = locale.substring(underscore + 1);
+ return new Locale(lang, cc);
+ }
return new Locale(locale);
}
diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.java b/src/main/java/com/gitblit/wicket/GitBlitWebApp.java
index 58fc5b7a..c4fdeda5 100644
--- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.java
+++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.java
@@ -41,7 +41,6 @@ import com.gitblit.manager.IRuntimeManager;
import com.gitblit.manager.IUserManager;
import com.gitblit.tickets.ITicketService;
import com.gitblit.transport.ssh.IPublicKeyManager;
-import com.gitblit.utils.StringUtils;
import com.gitblit.wicket.pages.ActivityPage;
import com.gitblit.wicket.pages.BlamePage;
import com.gitblit.wicket.pages.BlobDiffPage;
@@ -242,9 +241,9 @@ public class GitBlitWebApp extends WebApplication {
public final Session newSession(Request request, Response response) {
GitBlitWebSession gitBlitWebSession = new GitBlitWebSession(request);
- String forcedLocale = settings.getString(Keys.web.forceDefaultLocale, null);
- if (!StringUtils.isEmpty(forcedLocale)) {
- gitBlitWebSession.setLocale(new Locale(forcedLocale));
+ Locale forcedLocale = runtime().getLocale();
+ if (forcedLocale != null) {
+ gitBlitWebSession.setLocale(forcedLocale);
}
return gitBlitWebSession;
}
diff --git a/src/test/java/com/gitblit/tests/mock/MockRuntimeManager.java b/src/test/java/com/gitblit/tests/mock/MockRuntimeManager.java
index 8e518de5..6e56a873 100644
--- a/src/test/java/com/gitblit/tests/mock/MockRuntimeManager.java
+++ b/src/test/java/com/gitblit/tests/mock/MockRuntimeManager.java
@@ -17,6 +17,7 @@ package com.gitblit.tests.mock;
import java.io.File;
import java.util.Date;
+import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
@@ -71,6 +72,11 @@ public class MockRuntimeManager implements IRuntimeManager {
}
@Override
+ public Locale getLocale() {
+ return Locale.getDefault();
+ }
+
+ @Override
public boolean isServingRepositories() {
return true;
}