问题
I'm using JDK 13 for a Swing application but it won't show localized buttons for JOptionPane
:
public class test {
public static void main(String... args) {
Locale locale = Locale.forLanguageTag("es-MX");
Locale.setDefault(locale);
// JOptionPane.setDefaultLocale(locale);
// System.out.println(JOptionPane.getDefaultLocale());
JOptionPane.showConfirmDialog(null, "did it work?");
}
}
When using jre 1.8 it works as expected, displaying localized titles and buttons but not when using JDK 13.0.2
Java version "13.0.2" 2020-01-14
Java(TM) SE Runtime Environment (build 13.0.2+8)
Java HotSpot(TM) 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)
JOptionPane.getDefaultLocale()
do returns the correct locale es_MX
is just that it fails to localize the strings.
From what I've read, I think it has to do with the ResourceBundle
, I think JDK fails to load the bundle that corresponds to my locale.
And I don't know where to find such ResourceBundle and not really sure how to load it, maybe ResourceBundle.getBundle("somePathOrClassInsideJDK", locale);
?
I don't think that I need to create the ResourceBundle
from scratch, do I?
回答1:
JDK 11 Release Notes, Important Changes and Information says:
- Previous releases were translated into English, Japanese, and Simplified Chinese as well as French, German, Italian, Korean, Portuguese (Brazilian), Spanish, and Swedish. However, in JDK 11 and later, French, German, Italian, Korean, Portuguese (Brazilian), Spanish, and Swedish translations are no longer provided.
Reported as Bug JDK-8214574 (JOptionPane confirm dialog buttons are not localized), which was Closed as Duplicate of Bug JDK-8217485 (ModifiersExText not localized since JDK 11), which was Resolved as Won't Fix.
It is a result of Enhancement JDK-8204973 (Add build support for filtering translations), which states:
Oracle will reduce the number of languages that it maintains translations of JDK resources for. The current translations will remain in the source for now, but we need a way to filter out a set of translations at build time.
Oracle will use this configuration option to filter out all but English, Japanese, Simplified Chinese and Traditional Chinese.
来源:https://stackoverflow.com/questions/61699200/jdk-not-localizing-jcomponent