-
Enhancement
-
Resolution: Unresolved
-
P4
-
11, 12, 13
-
x86_64
-
windows_10
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.
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.
- relates to
-
JDK-8217485 ModifiersExText not localized since JDK 11
- Closed
-
JDK-8204973 Add build support for filtering translations
- Closed