JDK未本地化JComponent [英] JDK not localizing JComponent

查看:83
本文介绍了JDK未本地化JComponent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将JDK 13用于Swing应用程序,但不会显示 JOptionPane 的本地化按钮:

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?");
    }
}

使用jre 1.8时,它可以按预期工作,显示本地化的标题和按钮,但使用 JDK 13.0.2

When using jre 1.8 it works as expected, displaying localized titles and buttons but not when using JDK 13.0.2

Java版本"13.0.2"2020-01-14

Java version "13.0.2" 2020-01-14

Java(TM)SE运行时环境(内部版本13.0.2 + 8)

Java(TM) SE Runtime Environment (build 13.0.2+8)

Java HotSpot(TM)64位服务器VM(内部版本13.0.2 + 8,混合模式,共享)

Java HotSpot(TM) 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)

JOptionPane.getDefaultLocale()确实会返回正确的语言环境 es_MX ,只是它无法本地化字符串.

JOptionPane.getDefaultLocale() do returns the correct locale es_MX is just that it fails to localize the strings.

根据我的阅读,我认为这与 ResourceBundle 有关,我认为JDK无法加载与我的语言环境相对应的捆绑软件.

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.

我不知道在哪里可以找到这样的ResourceBundle,也不确定如何加载它,也许是 ResourceBundle.getBundle("somePathOrClassInsideJDK",locale); 吗?

And I don't know where to find such ResourceBundle and not really sure how to load it, maybe ResourceBundle.getBundle("somePathOrClassInsideJDK", locale); ?

我认为我不需要从头开始创建 ResourceBundle ,对吗?

I don't think that I need to create the ResourceBundle from scratch, do I?

推荐答案

JDK 11发行说明,重要更改和信息说:

  • 以前的版本已翻译成英语,日语和简体中文,以及法语,德语,意大利语,韩语,葡萄牙语(巴西),西班牙语和瑞典语.但是,在JDK 11及更高版本中,不再提供法语,德语,意大利语,韩语,葡萄牙语(巴西),西班牙语和瑞典语翻译.
  • .
  • 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.

报告为错误 JDK-8214574 (JOptionPane确认对话框按钮没有本地化),已作为错误无法修复.

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.

这是增强功能 JDK-8204973 的结果(添加了构建支持用于过滤翻译),其中指出:

It is a result of Enhancement JDK-8204973 (Add build support for filtering translations), which states:

Oracle将减少为其维护JDK资源翻译的语言数量.当前的翻译将暂时保留在源代码中,但是我们需要一种在构建时就过滤掉一组翻译的方法.

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将使用此配置选项来过滤除英语,日语,简体中文和繁体中文之外的所有内容.

Oracle will use this configuration option to filter out all but English, Japanese, Simplified Chinese and Traditional Chinese.

这篇关于JDK未本地化JComponent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆