最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Change locale of "native" MacOS menu items in a Java application - Stack Overflow

programmeradmin1浏览0评论

In order to improve the user experience for MacOS users, I use the "native" menubar, but the native/default menu items remain in English when I change the default locale.

I set System.setProperty("apple.laf.useScreenMenuBar", "true");

Further, I use System.setProperty("com.apple.mrj.application.apple.menu.about.name", "My app name);. I also use desktop.setQuitHandler(...) and desktop.setPreferenceHandler(...).

If I change the default Locale of my app to fr_FR for instance (Locale.setDefault(new Locale("fr", "FR"));), all my JMenu and JMenuItem are correctly translated in French (using a ResourceBundle for instance), but the "native" menu items ("About", "Quit", "Settings...") remain in English.

Is there a way to display these "native" menu items using another locale ?

In order to improve the user experience for MacOS users, I use the "native" menubar, but the native/default menu items remain in English when I change the default locale.

I set System.setProperty("apple.laf.useScreenMenuBar", "true");

Further, I use System.setProperty("com.apple.mrj.application.apple.menu.about.name", "My app name);. I also use desktop.setQuitHandler(...) and desktop.setPreferenceHandler(...).

If I change the default Locale of my app to fr_FR for instance (Locale.setDefault(new Locale("fr", "FR"));), all my JMenu and JMenuItem are correctly translated in French (using a ResourceBundle for instance), but the "native" menu items ("About", "Quit", "Settings...") remain in English.

Is there a way to display these "native" menu items using another locale ?

Share Improve this question asked Jan 31 at 17:52 Bart JourquinBart Jourquin 401 bronze badge 4
  • 1 Try starting the program with the LANG or LC_ALL environment variable set. You may also have success by setting the user.language and user.country system properties on the command line. (I do not understand the downvotes for this question. It’s a perfectly legitimate application design goal, and it clearly describes attempts to address the issue.) – VGR Commented Feb 1 at 14:22
  • First of all, I'd like to thank you for your kindness in formulating my question. I would also like to thank your various suggestions, which I had already explored. In trying to narrow down the problem, I realized that there's probably a problem with Java and the (latest? version of) MacOS. See below. – Bart Jourquin Commented Feb 3 at 12:01
  • I'm afraid you need to package your App in an App bundle and provide MacOS translation property files. First look at docs.oracle/javase/7/docs/technotes/guides/jweb/… – Jean-Baptiste Yunès Commented Feb 3 at 12:38
  • Thank you. This has been done and my entire application appears correctly in the language chosen by the user. The problem is only with “native” or “standard” elements such as JOprionPane, only on MacOS. Note also that the application has been in development for 20 years, and this problem has only recently appeared. – Bart Jourquin Commented Feb 3 at 13:55
Add a comment  | 

1 Answer 1

Reset to default 0

In trying to narrow down the problem, I realized that there's probably a problem with Java and the (latest? version of) MacOS. Indeed, the following snippet seems to indicate that not all Locale's work. In this case, Locale.FRANCE doesn't work (the “Cancel”, “No”, “Yes” buttons remain in English), whereas Locale.GERMANY does. The initial problem I described may be related to this.

import java.util.Locale;
import javax.swing.JOptionPane;

public class Test {
    public static void main(String[] args) {
        
        //Locale.setDefault(Locale.FRANCE); // Doesn't work
        Locale.setDefault(Locale.GERMANY); // Works !
        
        JOptionPane.showConfirmDialog(null, "Message");
    }

}
发布评论

评论列表(0)

  1. 暂无评论