Bug 63143

Summary: Respect client's browser preference for English language (can be fixed by providing empty LocalStrings_en.properties files)
Product: Tomcat 9 Reporter: Konstantin Kolinko <knst.kolinko>
Component: ManagerAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 9.0.14   
Target Milestone: -----   
Hardware: PC   
OS: All   

Description Konstantin Kolinko 2019-02-04 13:10:43 UTC
The manager web application does not select English language according to user's preferences in some configurations, unless you create an empty LocalStrings_en.properties" file to enable English locale.

It is an issue with bundle selection in org.apache.tomcat.util.res.StringManager.getManager(String, Enumeration<Locale>).


Steps to reproduce:

Using Tomcat 9.0.15 (trunk), Java 8, Mozilla Firefox.

1. Run JVM with an OS of a language that Tomcat has a translation available.

My OS uses Russian language.

2. Configure a browser, to send "en" as the preferred language.

E.g., I configure the browser with the following list of languages:

en
en-us
ru-ru
ru

3. Start Tomcat, start the browser and access the Manager web application.

Expected: I expect the UI to be in English language.
Actual: The UI is in Russian language.

WORKAROUND:

If I create an empty LocalStrings_en.properties file in ${catalina.home}/lib/**, I get the expected result: the UI is in English language. Path to the file:

${catalina.home}/lib/org/apache/catalina/manager/LocalStrings_en.properties


GUESS:

Looking into StringManager class constructor, when it gets a bundle that has Locale.ROOT it interprets it as Locale.ENGLISH. It is OK.

If I remember correctly, in this case Java actually falls back to the system default locale. That is: when you request a resource in English locale (that does not exist), Java returns a resource in the system default locale (Russian in my case) and not the ROOT locale one.

It would be better to fix this in StringManager, instead of having to maintain a lot of empty files.
Comment 1 Mark Thomas 2019-02-04 15:15:34 UTC
Fixed in:
- trunk for 9.0.16 onwards
- 8.5.x for 8.5.38 onwards
- 7.0.x for 7.0.93 onwards
Comment 2 Christopher Schultz 2019-02-08 00:24:14 UTC
I didn't look at Mark's fix, but at $work, we always work on Bundle_en.properties for English. At build time, we specify the "Default locale" and copy Bundle_[locale].properties to Bundle.properties.