summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFlorian Zschocke <florian.zschocke@devolo.de>2019-11-11 18:13:11 +0100
committerFlorian Zschocke <florian.zschocke@devolo.de>2019-11-11 18:13:11 +0100
commite5f29381eca3f28ef5792225516bbea7a3773898 (patch)
treed0ddbdfde94baefca4d1e2f9547bd685898d5672 /src
parentc4698341d75ef4adc38ebbc3bfbca81bf0ed80dc (diff)
downloadgitblit-e5f29381eca3f28ef5792225516bbea7a3773898.tar.gz
gitblit-e5f29381eca3f28ef5792225516bbea7a3773898.zip
Fix user preferences selecting the wrong preferred locale.
Due to a wrong comparison, when loading the preferred locale in the user preferences page, in cases like `zh_CN` or `de_DE` the wrong locale would be chosen. As with too many things, the code is duplicated on the `UserPage` and the `EditUserPage`. And they differ. So extract the choosing of the preferred language for display into a method in the (more up-to-date) `UserPage` and call that from the `EditUserPage`.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/gitblit/wicket/pages/EditUserPage.java25
-rw-r--r--src/main/java/com/gitblit/wicket/pages/UserPage.java49
2 files changed, 28 insertions, 46 deletions
diff --git a/src/main/java/com/gitblit/wicket/pages/EditUserPage.java b/src/main/java/com/gitblit/wicket/pages/EditUserPage.java
index 5b0b0147..c6014e8f 100644
--- a/src/main/java/com/gitblit/wicket/pages/EditUserPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/EditUserPage.java
@@ -112,30 +112,11 @@ public class EditUserPage extends RootSubPage {
final Palette<String> teams = new Palette<String>("teams", new ListModel<String>(
new ArrayList<String>(userTeams)), new CollectionModel<String>(app().users()
.getAllTeamNames()), new StringChoiceRenderer(), 10, false);
- Locale locale = userModel.getPreferences().getLocale();
- if (locale == null) {
- locale = Locale.ENGLISH;
- }
+ Locale locale = userModel.getPreferences().getLocale();
List<Language> languages = UserPage.getLanguages();
- Language preferredLanguage = null;
- if (locale != null) {
- String localeCode = locale.getLanguage();
- if (!StringUtils.isEmpty(locale.getCountry())) {
- localeCode += "_" + locale.getCountry();
- }
-
- for (Language lang : languages) {
- if (lang.code.equals(localeCode)) {
- // language_COUNTRY match
- preferredLanguage = lang;
- } else if (preferredLanguage != null && lang.code.startsWith(locale.getLanguage())) {
- // language match
- preferredLanguage = lang;
- }
- }
- }
- final IModel<Language> language = Model.of(preferredLanguage);
+ Language preferredLanguage = UserPage.getPreferredLanguage(locale, languages);
+ final IModel<Language> language = Model.of(preferredLanguage);
Form<UserModel> form = new Form<UserModel>("editForm", model) {
private static final long serialVersionUID = 1L;
diff --git a/src/main/java/com/gitblit/wicket/pages/UserPage.java b/src/main/java/com/gitblit/wicket/pages/UserPage.java
index b457304b..4fc778a6 100644
--- a/src/main/java/com/gitblit/wicket/pages/UserPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/UserPage.java
@@ -15,7 +15,6 @@
*/
package com.gitblit.wicket.pages;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -167,7 +166,7 @@ public class UserPage extends RootPage {
navLinks.add(menu);
}
- public static List<Language> getLanguages(){
+ static List<Language> getLanguages(){
return Arrays.asList(
new Language("Česky","cs"),
new Language("Deutsch","de"),
@@ -184,13 +183,32 @@ public class UserPage extends RootPage {
new Language("簡體中文", "zh_CN"),
new Language("正體中文", "zh_TW"));
}
-
+
+ static Language getPreferredLanguage(Locale locale, List<Language> languages) {
+ Language preferredLanguage = null;
+ if (locale != null) {
+ String localeCode = locale.getLanguage();
+ if (!StringUtils.isEmpty(locale.getCountry())) {
+ localeCode += "_" + locale.getCountry();
+ }
+
+ for (Language language : languages) {
+ if (language.code.equals(localeCode)) {
+ // language_COUNTRY match
+ preferredLanguage = language;
+ } else if (preferredLanguage == null && language.code.startsWith(locale.getLanguage())) {
+ // language match
+ preferredLanguage = language;
+ }
+ }
+ }
+ return preferredLanguage;
+ }
+
private void addPreferences(UserModel user) {
// add preferences
Form<Void> prefs = new Form<Void>("prefsForm");
- List<Language> languages = getLanguages();
-
Locale locale = user.getPreferences().getLocale();
if (locale == null) {
// user has not specified language preference
@@ -203,28 +221,11 @@ public class UserPage extends RootPage {
if (sessionLocale != null) {
locale = sessionLocale;
}
- } else {
-
}
}
- Language preferredLanguage = null;
- if (locale != null) {
- String localeCode = locale.getLanguage();
- if (!StringUtils.isEmpty(locale.getCountry())) {
- localeCode += "_" + locale.getCountry();
- }
-
- for (Language language : languages) {
- if (language.code.equals(localeCode)) {
- // language_COUNTRY match
- preferredLanguage = language;
- } else if (preferredLanguage != null && language.code.startsWith(locale.getLanguage())) {
- // language match
- preferredLanguage = language;
- }
- }
- }
+ List<Language> languages = getLanguages();
+ Language preferredLanguage = getPreferredLanguage(locale, languages);
final IModel<String> displayName = Model.of(user.getDisplayName());
final IModel<String> emailAddress = Model.of(user.emailAddress == null ? "" : user.emailAddress);