final Palette<String> teams = new Palette<String>("teams", new ListModel<String>(\r
new ArrayList<String>(userTeams)), new CollectionModel<String>(app().users()\r
.getAllTeamNames()), new StringChoiceRenderer(), 10, false);\r
- Locale locale = userModel.getPreferences().getLocale();\r
- if (locale == null) {\r
- locale = Locale.ENGLISH;\r
- }\r
\r
+ Locale locale = userModel.getPreferences().getLocale();\r
List<Language> languages = UserPage.getLanguages();\r
- Language preferredLanguage = null;\r
- if (locale != null) {\r
- String localeCode = locale.getLanguage();\r
- if (!StringUtils.isEmpty(locale.getCountry())) {\r
- localeCode += "_" + locale.getCountry();\r
- }\r
-\r
- for (Language lang : languages) {\r
- if (lang.code.equals(localeCode)) {\r
- // language_COUNTRY match\r
- preferredLanguage = lang;\r
- } else if (preferredLanguage != null && lang.code.startsWith(locale.getLanguage())) {\r
- // language match\r
- preferredLanguage = lang;\r
- }\r
- }\r
- }\r
- final IModel<Language> language = Model.of(preferredLanguage); \r
+ Language preferredLanguage = UserPage.getPreferredLanguage(locale, languages);\r
+ final IModel<Language> language = Model.of(preferredLanguage);\r
Form<UserModel> form = new Form<UserModel>("editForm", model) {\r
\r
private static final long serialVersionUID = 1L;\r
*/\r
package com.gitblit.wicket.pages;\r
\r
-import java.io.Serializable;\r
import java.util.ArrayList;\r
import java.util.Arrays;\r
import java.util.Collections;\r
navLinks.add(menu);\r
}\r
\r
- public static List<Language> getLanguages(){\r
+ static List<Language> getLanguages(){\r
return Arrays.asList(\r
new Language("Česky","cs"),\r
new Language("Deutsch","de"),\r
new Language("簡體中文", "zh_CN"),\r
new Language("正體中文", "zh_TW"));\r
}\r
- \r
+\r
+ static Language getPreferredLanguage(Locale locale, List<Language> languages) {\r
+ Language preferredLanguage = null;\r
+ if (locale != null) {\r
+ String localeCode = locale.getLanguage();\r
+ if (!StringUtils.isEmpty(locale.getCountry())) {\r
+ localeCode += "_" + locale.getCountry();\r
+ }\r
+\r
+ for (Language language : languages) {\r
+ if (language.code.equals(localeCode)) {\r
+ // language_COUNTRY match\r
+ preferredLanguage = language;\r
+ } else if (preferredLanguage == null && language.code.startsWith(locale.getLanguage())) {\r
+ // language match\r
+ preferredLanguage = language;\r
+ }\r
+ }\r
+ }\r
+ return preferredLanguage;\r
+ }\r
+\r
private void addPreferences(UserModel user) {\r
// add preferences\r
Form<Void> prefs = new Form<Void>("prefsForm");\r
\r
- List<Language> languages = getLanguages();\r
-\r
Locale locale = user.getPreferences().getLocale();\r
if (locale == null) {\r
// user has not specified language preference\r
if (sessionLocale != null) {\r
locale = sessionLocale;\r
}\r
- } else {\r
-\r
}\r
}\r
\r
- Language preferredLanguage = null;\r
- if (locale != null) {\r
- String localeCode = locale.getLanguage();\r
- if (!StringUtils.isEmpty(locale.getCountry())) {\r
- localeCode += "_" + locale.getCountry();\r
- }\r
-\r
- for (Language language : languages) {\r
- if (language.code.equals(localeCode)) {\r
- // language_COUNTRY match\r
- preferredLanguage = language;\r
- } else if (preferredLanguage != null && language.code.startsWith(locale.getLanguage())) {\r
- // language match\r
- preferredLanguage = language;\r
- }\r
- }\r
- }\r
+ List<Language> languages = getLanguages();\r
+ Language preferredLanguage = getPreferredLanguage(locale, languages);\r
\r
final IModel<String> displayName = Model.of(user.getDisplayName());\r
final IModel<String> emailAddress = Model.of(user.emailAddress == null ? "" : user.emailAddress);\r