-
Notifications
You must be signed in to change notification settings - Fork 4k
TRUNK-6341: Improved locale matching by using Locale.filter() for bes… #5485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
ibacher
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to add some tests for this?
| import java.util.ResourceBundle; | ||
| import java.util.Set; | ||
|
|
||
| import java.util.List; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make sure your IDE is configured to use the standard OpenMRS coding scheme. That should eliminate the blank line changes and put this in the right place or you can do that manually.
| * @param request the incoming HTTP request containing the Accept-Language header | ||
| * @return the best matching available locale based on the requests 'Accept-Language' header | ||
| */ | ||
| public Locale findBestLocale(HttpServletRequest request) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also use this in the update filter, I suppose...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will do it.
| CustomResourceLoader resourceLoader = CustomResourceLoader.getInstance(httpRequest); | ||
|
|
||
| Locale bestLocale = resourceLoader.findBestLocale(httpRequest); | ||
|
|
||
| httpRequest.getSession().setAttribute(FilterUtil.LOCALE_ATTRIBUTE, bestLocale.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like this could be simplified or at least the added whitespace lines removed.
| httpRequest.getSession().setAttribute(FilterUtil.LOCALE_ATTRIBUTE, Locale.ENGLISH.toString()); | ||
| } | ||
| } | ||
| public void checkLocaleAttributesForFirstTime(HttpServletRequest httpRequest) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the indentation changed here?
|
Also, in the future, the PR template is there to help reviewers review your PR. Please do not ignore it. |
This PR improves locale selection logic used during initialization.Previously, the filter only checked if the user’s preferred locale was directly present in available locales using contains().This caused issues for regional variants like fr-BE, which fell back to English even when fr translations existed.The new implementation uses Locale.LanguageRange.parse() and Locale.filter() to find the best available match, falling back to English only if no match is found.
No new tests added since the issue is low priority and no existing test class for this component.