JDK-8221660 : Enforce locale used to translate displayed menu keyboard shortcuts
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt:i18n
  • Affected Version: 11,12,13
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2019-03-25
  • Updated: 2019-03-29
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Java 11 (or older), Windows 10 (or older)

A DESCRIPTION OF THE PROBLEM :
Let's say I have installed an English Windows OS (which has the entire UI in English). And I want in a started Java application, based on its own internal application settings to force the default locale used for translating shortcut keys to be for example German by using: Locale.setDefault(new Locale("de", "DE"));
Methods like this "java.awt.event.KeyEvent.getKeyModifiersText(int)" delegate to the "Toolkit.getProperty(String, String)" which uses an internal "java.awt.Toolkit.resources" field which is initialized very early and is impossible to change from the outside except by using Java reflection.

So I need some kind of new method "Toolkit.setLocale(newLocale)" which could be used to re-initialize the "resources" field set inside it.

Sample code:

public static void main(String[] args) { 
	Locale.setDefault(new Locale("de", "DE"));
	JMenuItem jmi = new JMenuItem("some text");
	jmi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, KeyEvent.SHIFT_MASK));

	JFrame frame = new JFrame();
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.setSize(400, 400);
	frame.getContentPane().add(jmi);
	frame.setVisible(true);
}

when you open the top menu the menu item should have the shortcut shown translated in the German language.



Comments
Even if resource will be reinitialized it does not help, ITALIAN/GERMAN locales are not supported anymore, and since jdk11+ the resource file does not have corresponding data: https://bugs.openjdk.java.net/browse/JDK-8217485 https://bugs.openjdk.java.net/browse/JDK-8204973
29-03-2019

This is a request to support forcing the default locale to be used for translating shortcut keys in a Java application. Attached test case (checked) with demonstrate the required.
29-03-2019