diff options
author | Florian Zschocke <florian.zschocke@devolo.de> | 2019-11-11 18:13:11 +0100 |
---|---|---|
committer | Florian Zschocke <florian.zschocke@devolo.de> | 2019-11-11 18:13:11 +0100 |
commit | e5f29381eca3f28ef5792225516bbea7a3773898 (patch) | |
tree | d0ddbdfde94baefca4d1e2f9547bd685898d5672 /src/main/java/com/gitblit/wicket/pages/EditUserPage.java | |
parent | c4698341d75ef4adc38ebbc3bfbca81bf0ed80dc (diff) | |
download | gitblit-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/main/java/com/gitblit/wicket/pages/EditUserPage.java')
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/EditUserPage.java | 25 |
1 files changed, 3 insertions, 22 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;
|