Skip to content

Conversation

@KRISHNAPATIL19
Copy link

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.

Copy link
Member

@ibacher ibacher left a 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;
Copy link
Member

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) {
Copy link
Member

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...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do it.

Comment on lines +997 to +1001
CustomResourceLoader resourceLoader = CustomResourceLoader.getInstance(httpRequest);

Locale bestLocale = resourceLoader.findBestLocale(httpRequest);

httpRequest.getSession().setAttribute(FilterUtil.LOCALE_ATTRIBUTE, bestLocale.toString());
Copy link
Member

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) {
Copy link
Member

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?

@ibacher
Copy link
Member

ibacher commented Nov 12, 2025

Also, in the future, the PR template is there to help reviewers review your PR. Please do not ignore it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants