diff options
author | James Moger <james.moger@gitblit.com> | 2014-06-05 10:20:59 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-06-05 10:20:59 -0400 |
commit | 6537deb8b76b7a4725c40a174a7c440385f88e51 (patch) | |
tree | 78399974a6de9599e63373459e90da41fd16532d /src/main/java | |
parent | 05f229883c4e15e044c5c103acf69265cfb8806e (diff) | |
download | gitblit-6537deb8b76b7a4725c40a174a7c440385f88e51.tar.gz gitblit-6537deb8b76b7a4725c40a174a7c440385f88e51.zip |
Revise language/locale preference handling
Diffstat (limited to 'src/main/java')
4 files changed, 29 insertions, 14 deletions
diff --git a/src/main/java/com/gitblit/ConfigUserService.java b/src/main/java/com/gitblit/ConfigUserService.java index 9b4dd7f1..b5dfde3b 100644 --- a/src/main/java/com/gitblit/ConfigUserService.java +++ b/src/main/java/com/gitblit/ConfigUserService.java @@ -707,8 +707,9 @@ public class ConfigUserService implements IUserService { config.setBoolean(USER, model.username, DISABLED, true);
}
if (model.getPreferences() != null) {
- if (!StringUtils.isEmpty(model.getPreferences().locale)) {
- config.setString(USER, model.username, LOCALE, model.getPreferences().locale);
+ if (model.getPreferences().getLocale() != null) {
+ String val = model.getPreferences().getLocale().getLanguage() + "_" + model.getPreferences().getLocale().getCountry();
+ config.setString(USER, model.username, LOCALE, val);
}
}
@@ -880,11 +881,13 @@ public class ConfigUserService implements IUserService { user.stateProvince = config.getString(USER, username, STATEPROVINCE);
user.countryCode = config.getString(USER, username, COUNTRYCODE);
user.cookie = config.getString(USER, username, COOKIE);
- user.getPreferences().locale = config.getString(USER, username, LOCALE);
if (StringUtils.isEmpty(user.cookie) && !StringUtils.isEmpty(user.password)) {
user.cookie = StringUtils.getSHA1(user.username + user.password);
}
+ // preferences
+ user.getPreferences().setLocale(config.getString(USER, username, LOCALE));
+
// user roles
Set<String> roles = new HashSet<String>(Arrays.asList(config.getStringList(
USER, username, ROLE)));
diff --git a/src/main/java/com/gitblit/models/UserPreferences.java b/src/main/java/com/gitblit/models/UserPreferences.java index 44e44933..61db353c 100644 --- a/src/main/java/com/gitblit/models/UserPreferences.java +++ b/src/main/java/com/gitblit/models/UserPreferences.java @@ -37,7 +37,7 @@ public class UserPreferences implements Serializable { public final String username; - public String locale; + private String locale; private final Map<String, UserRepositoryPreferences> repositoryPreferences = new TreeMap<String, UserRepositoryPreferences>(); @@ -58,6 +58,10 @@ public class UserPreferences implements Serializable { return new Locale(locale); } + public void setLocale(String locale) { + this.locale = locale; + } + public UserRepositoryPreferences getRepositoryPreferences(String repositoryName) { String key = repositoryName.toLowerCase(); if (!repositoryPreferences.containsKey(key)) { diff --git a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties index 7dc0f9b6..90d30f29 100644 --- a/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties +++ b/src/main/java/com/gitblit/wicket/GitBlitWebApp.properties @@ -727,7 +727,7 @@ gb.preferences = preferences gb.accountPreferences = Account Preferences gb.accountPreferencesDescription = Specify your account preferences gb.languagePreference = Language Preference -gb.languagePreferenceDescription = Select your preferred translation for the Gitblit UI +gb.languagePreferenceDescription = Select your preferred translation for Gitblit gb.displayNameDescription = The preferred name for display gb.emailAddressDescription = The primary email address for receiving notifications gb.sshKeys = SSH Keys diff --git a/src/main/java/com/gitblit/wicket/pages/UserPage.java b/src/main/java/com/gitblit/wicket/pages/UserPage.java index 4a955c7c..94048963 100644 --- a/src/main/java/com/gitblit/wicket/pages/UserPage.java +++ b/src/main/java/com/gitblit/wicket/pages/UserPage.java @@ -181,28 +181,36 @@ public class UserPage extends RootPage { new Language("Português", "pt_BR"),
new Language("中文", "zh_CN"));
- String lc = user.getPreferences().locale;
- if (StringUtils.isEmpty(lc)) {
+ Locale locale = user.getPreferences().getLocale();
+ if (locale == null) {
// user has not specified language preference
// try server default preference
- lc = app().settings().getString(Keys.web.forceDefaultLocale, null);
+ String lc = app().settings().getString(Keys.web.forceDefaultLocale, null);
if (StringUtils.isEmpty(lc)) {
// server default language is not configured
// try browser preference
Locale sessionLocale = GitBlitWebSession.get().getLocale();
if (sessionLocale != null) {
- lc = sessionLocale.getLanguage() + "_" + sessionLocale.getCountry();
+ locale = sessionLocale;
}
+ } else {
+
}
}
+
Language preferredLanguage = null;
- if (!StringUtils.isEmpty(lc)) {
+ if (locale != null) {
+ String localeCode = locale.getLanguage();
+ if (!StringUtils.isEmpty(locale.getCountry())) {
+ localeCode += "_" + locale.getCountry();
+ }
+
for (Language language : languages) {
- if (language.code.equals(lc)) {
+ if (language.code.equals(localeCode)) {
// language_COUNTRY match
preferredLanguage = language;
- } else if (preferredLanguage != null && lc.startsWith(language.code)) {
- // language match, but not COUNTRY match
+ } else if (preferredLanguage != null && language.code.startsWith(locale.getLanguage())) {
+ // language match
preferredLanguage = language;
}
}
@@ -242,7 +250,7 @@ public class UserPage extends RootPage { Language lang = language.getObject();
if (lang != null) {
- user.getPreferences().locale = lang.code;
+ user.getPreferences().setLocale(lang.code);
}
try {
|