diff options
author | william <william.fromtw@gmail.com> | 2017-02-08 08:35:01 +0800 |
---|---|---|
committer | william <william.fromtw@gmail.com> | 2017-02-08 08:35:01 +0800 |
commit | 2e68cb6eb7f943379aa4f8a40854bc9dfd8d9bc4 (patch) | |
tree | e11dabfad514d5d90afc0e5b445741cbe7f411a3 | |
parent | 06f23c3c476d02c5e7899ed5ada798bcafa7b4ff (diff) | |
download | gitblit-2e68cb6eb7f943379aa4f8a40854bc9dfd8d9bc4.tar.gz gitblit-2e68cb6eb7f943379aa4f8a40854bc9dfd8d9bc4.zip |
New Setting "Default Language" when creating user.
4 files changed, 71 insertions, 29 deletions
diff --git a/src/main/java/com/gitblit/wicket/pages/EditUserPage.html b/src/main/java/com/gitblit/wicket/pages/EditUserPage.html index 3bccdd59..48e5339f 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditUserPage.html +++ b/src/main/java/com/gitblit/wicket/pages/EditUserPage.html @@ -31,11 +31,12 @@ <tr><th><wicket:message key="gb.confirmPassword"></wicket:message></th><td class="edit"><input type="password" wicket:id="confirmPassword" size="30" tabindex="3" /></td></tr>
<tr><th><wicket:message key="gb.displayName"></wicket:message></th><td class="edit"><input type="text" wicket:id="displayName" size="30" tabindex="4" /></td></tr>
<tr><th><wicket:message key="gb.emailAddress"></wicket:message></th><td class="edit"><input type="text" wicket:id="emailAddress" size="30" tabindex="5" /></td></tr>
- <tr><th><wicket:message key="gb.canAdmin"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="canAdmin" tabindex="6" /> <span class="help-inline"><wicket:message key="gb.canAdminDescription"></wicket:message></span></label></td></tr>
- <tr><th><wicket:message key="gb.canCreate"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="canCreate" tabindex="7" /> <span class="help-inline"><wicket:message key="gb.canCreateDescription"></wicket:message></span></label></td></tr>
- <tr><th><wicket:message key="gb.canFork"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="canFork" tabindex="8" /> <span class="help-inline"><wicket:message key="gb.canForkDescription"></wicket:message></span></label></td></tr>
- <tr><th><wicket:message key="gb.excludeFromFederation"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="excludeFromFederation" tabindex="9" /> <span class="help-inline"><wicket:message key="gb.excludeFromFederationDescription"></wicket:message></span></label></td></tr>
- <tr><th><wicket:message key="gb.disableUser"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="disabled" tabindex="10" /> <span class="help-inline"><wicket:message key="gb.disableUserDescription"></wicket:message></span></label></td></tr>
+ <tr><th><wicket:message key="gb.languagePreference"></wicket:message></th><td class="edit"><select wicket:id="language" ></select></td></tr>
+ <tr><th><wicket:message key="gb.canAdmin"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="canAdmin" tabindex="7" /> <span class="help-inline"><wicket:message key="gb.canAdminDescription"></wicket:message></span></label></td></tr>
+ <tr><th><wicket:message key="gb.canCreate"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="canCreate" tabindex="8" /> <span class="help-inline"><wicket:message key="gb.canCreateDescription"></wicket:message></span></label></td></tr>
+ <tr><th><wicket:message key="gb.canFork"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="canFork" tabindex="9" /> <span class="help-inline"><wicket:message key="gb.canForkDescription"></wicket:message></span></label></td></tr>
+ <tr><th><wicket:message key="gb.excludeFromFederation"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="excludeFromFederation" tabindex="10" /> <span class="help-inline"><wicket:message key="gb.excludeFromFederationDescription"></wicket:message></span></label></td></tr>
+ <tr><th><wicket:message key="gb.disableUser"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="disabled" tabindex="11" /> <span class="help-inline"><wicket:message key="gb.disableUserDescription"></wicket:message></span></label></td></tr>
</tbody>
</table>
</div>
diff --git a/src/main/java/com/gitblit/wicket/pages/EditUserPage.java b/src/main/java/com/gitblit/wicket/pages/EditUserPage.java index 72dee6b6..0a6981b3 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditUserPage.java +++ b/src/main/java/com/gitblit/wicket/pages/EditUserPage.java @@ -20,15 +20,18 @@ import java.util.ArrayList; import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import java.util.Locale;
import org.apache.wicket.PageParameters;
import org.apache.wicket.behavior.SimpleAttributeModifier;
import org.apache.wicket.extensions.markup.html.form.palette.Palette;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.CheckBox;
+import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.CompoundPropertyModel;
+import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.util.CollectionModel;
import org.apache.wicket.model.util.ListModel;
@@ -108,6 +111,30 @@ 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;
+ }
+
+ 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);
Form<UserModel> form = new Form<UserModel>("editForm", model) {
private static final long serialVersionUID = 1L;
@@ -123,6 +150,10 @@ public class EditUserPage extends RootSubPage { error(getString("gb.pleaseSetUsername"));
return;
}
+ Language lang = language.getObject();
+ if (lang != null) {
+ userModel.getPreferences().setLocale(lang.code);
+ }
// force username to lower-case
userModel.username = userModel.username.toLowerCase();
String username = userModel.username;
@@ -251,7 +282,10 @@ public class EditUserPage extends RootSubPage { form.add(confirmPasswordField.setEnabled(editCredentials));
form.add(new TextField<String>("displayName").setEnabled(editDisplayName));
form.add(new TextField<String>("emailAddress").setEnabled(editEmailAddress));
+
+ DropDownChoice<Language> choice = new DropDownChoice<Language>("language",language,languages );
+ form.add( choice.setEnabled(languages.size()>0) );
if (userModel.canAdmin() && !userModel.canAdmin) {
// user inherits Admin permission
// display a disabled-yet-checked checkbox
diff --git a/src/main/java/com/gitblit/wicket/pages/Language.java b/src/main/java/com/gitblit/wicket/pages/Language.java new file mode 100644 index 00000000..6eafb4dc --- /dev/null +++ b/src/main/java/com/gitblit/wicket/pages/Language.java @@ -0,0 +1,21 @@ +package com.gitblit.wicket.pages; + +import java.io.Serializable; + +public class Language implements Serializable { + + private static final long serialVersionUID = 1L; + + final String name; + final String code; + + public Language(String name, String code) { + this.name = name; + this.code = code; + } + + @Override + public String toString() { + return name + " (" + code + ")"; + } +}
\ No newline at end of file diff --git a/src/main/java/com/gitblit/wicket/pages/UserPage.java b/src/main/java/com/gitblit/wicket/pages/UserPage.java index ea68f25b..25a2249b 100644 --- a/src/main/java/com/gitblit/wicket/pages/UserPage.java +++ b/src/main/java/com/gitblit/wicket/pages/UserPage.java @@ -166,12 +166,9 @@ public class UserPage extends RootPage { navLinks.add(menu);
}
-
- private void addPreferences(UserModel user) {
- // add preferences
- Form<Void> prefs = new Form<Void>("prefsForm");
-
- List<Language> languages = Arrays.asList(
+
+ public static List<Language> getLanguages(){
+ return Arrays.asList(
new Language("Deutsch","de"),
new Language("English","en"),
new Language("Español", "es"),
@@ -185,6 +182,13 @@ public class UserPage extends RootPage { new Language("Português", "pt_BR"),
new Language("簡體中文", "zh_CN"),
new Language("正體中文", "zh_TW"));
+ }
+
+ 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) {
@@ -315,22 +319,4 @@ public class UserPage extends RootPage { add(new Fragment("sshKeysLink", "sshKeysLinkFragment", this).setRenderBodyOnly(true));
add(keysTab.setRenderBodyOnly(true));
}
-
- private class Language implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- final String name;
- final String code;
-
- public Language(String name, String code) {
- this.name = name;
- this.code = code;
- }
-
- @Override
- public String toString() {
- return name + " (" + code +")";
- }
- }
}
|