OF-3137: setup page: select locale from browser#3050
Open
stokito wants to merge 7 commits into
Open
Conversation
This will use the JVM's default locale instead.
b7077cc to
ea657d4
Compare
ea657d4 to
3718b94
Compare
Member
|
@stokito Sorry that this PR has languished. Have requested AI review and lets see about getting it considered for Openfire 5.1 |
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates Openfire setup/admin locale selection to prefer the user’s browser locale and centralizes the list of supported locales.
Changes:
- Add supported-locale registry and “best match” selection logic in
LocaleUtils. - Update setup and server-locale JSPs to render locale choices from the supported-locale registry (and preselect based on browser locale in setup).
- Adjust default locale configuration and add/extend unit tests.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| xmppserver/src/main/java/org/jivesoftware/util/LocaleUtils.java | Adds supported locale registry and browser-locale matching helper; minor RTL check simplification. |
| xmppserver/src/main/webapp/setup/index.jsp | Uses supported locales + browser locale matching to preselect setup language; removes hardcoded locale list. |
| xmppserver/src/main/webapp/server-locale.jsp | Uses supported locales map to render language selection and display current language name. |
| xmppserver/src/test/java/org/jivesoftware/util/LocaleUtilsTest.java | Adds unit test coverage for the new locale matching logic. |
| distribution/src/conf/openfire.xml | Changes default configured locale value to empty. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+278
to
+305
| // build lang codes haystack "pt_BR pt_PT pt_ " | ||
| String localesList = ""; | ||
| while (requestLocales.hasMoreElements()){ | ||
| Locale locale = requestLocales.nextElement(); | ||
| localesList += locale.getLanguage() + "_" + locale.getCountry() + " "; | ||
| } | ||
| int bestMatchPos = Integer.MAX_VALUE; | ||
| String matchedLocale = null; | ||
| for (Map.Entry<String, String> entry : supportedLocales.entrySet()) { | ||
| // first match by lang and country, if no then try to match by only language | ||
| String localeCode = entry.getKey(); // e.g. pt_BR | ||
| int matchPos = localesList.indexOf(localeCode + " "); | ||
| if (matchPos < 0) { | ||
| // match by lang only i.e, no country | ||
| String lang = substringBefore(localeCode, "_"); | ||
| matchPos = localesList.indexOf(lang + "_ "); | ||
| if (matchPos < 0) { | ||
| continue; | ||
| } | ||
| } | ||
| if (matchPos < bestMatchPos) { | ||
| bestMatchPos = matchPos; | ||
| matchedLocale = localeCode; | ||
| } | ||
| } | ||
| if (matchedLocale != null) { | ||
| return matchedLocale; | ||
| } |
Comment on lines
+279
to
+283
| String localesList = ""; | ||
| while (requestLocales.hasMoreElements()){ | ||
| Locale locale = requestLocales.nextElement(); | ||
| localesList += locale.getLanguage() + "_" + locale.getCountry() + " "; | ||
| } |
| * Get list of locales (code: name) that the web admin has translations for. | ||
| */ | ||
| public static Map<String, String> getSupportedLocales() { | ||
| return supportedLocales; |
| <div class="jive-contentBox"> | ||
| <p> | ||
| <b><fmt:message key="locale.current" />:</b> <%= locale.getDisplayName(locale) %> / | ||
| <b><fmt:message key="locale.current" />:</b> ${locales[locale]} / |
Comment on lines
+25
to
26
| <locale></locale> | ||
|
|
Comment on lines
+20
to
+23
| import java.util.Collections; | ||
| import java.util.Enumeration; | ||
| import java.util.List; | ||
| import java.util.Locale; |
Comment on lines
+40
to
+47
| public void bestMatchingSupportedLocale() { | ||
| Enumeration<Locale> reqLocales = Collections.enumeration(asList( | ||
| new Locale("pt", "BR"), | ||
| new Locale("pt", "PT"), | ||
| new Locale("pt") | ||
| )); | ||
| String preferredLocale = LocaleUtils.bestMatchingSupportedLocale(reqLocales); | ||
| assertThat(preferredLocale, is("pt_BR")); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://igniterealtime.atlassian.net/browse/OF-3137
During the Openfire set up the list of languages can be simplified and improved.
Currently during installation the language selector is always pre-selected on English. The server may have another locale, but the best way would be to set same locale as a user browser.
Also it would be better to make list of supported locales easier to modify.