简体   繁体   English

JavaFX 2和国际化加载属性文件

[英]JavaFX 2 and Internationalization loading properties files

how to load multiple ResourceBundle files i have multiple fxml files and for every file i created a properties file eg: top.fxml top.properties how to load all the properties files ? 如何加载多个ResourceBundle文件我有多个fxml文件,因此我为每个文件创建了一个属性文件,例如:top.fxml top.properties如何加载所有属性文件?

I try something like that but its not working 我尝试这样的事情,但不起作用

    Locale locale = new Locale("fr", "FR");
    ResourceBundle bundle = ResourceBundle.getBundle("i18n.bottom", locale);
    ResourceBundle bundle2 = ResourceBundle.getBundle("i18n.top", locale);

    FXMLLoader loader = new FXMLLoader(getClass().getResource("main.fxml"));
    loader.setResources(bundle);
    loader.setResources(bundle2);
    Parent root = loader.load();

I didn't try it, but it should just be as simple as setting the bundle each time before you load: 我没有尝试过,但是应该就像每次加载之前设置捆绑包一样简单:

FXMLLoader loader = new FXMLLoader(getClass().getResource("main.fxml"));
loader.setResources(bundle);
Parent firstBundleRoot = loader.load();
loader.setResources(bundle2);
Parent secondBundleRoot = loader.load();

Note that this assumes that what you are trying to do is generate multiple node trees for the different bundles, each of which is customized by different bundle text (which may not be what you want). 请注意,这假设您要尝试为不同的包生成多个节点树,每个节点树都是由不同的包文本(可能不是您想要的)自定义的。

I do get the feeling that I may have missed something in your question... 我确实感到我可能错过了您的问题中的某些内容。


Perhaps you are trying to do the following? 也许您正在尝试执行以下操作?

Which I think is a solution to create some kind of mega-resource bundle that includes merged resources from various resource bundles. 我认为这是创建某种大型资源束的解决方案,其中包括来自各种资源束的合并资源。 So, if this is the case, rather than loading each bundle separately and loading the FXML each time, resulting in multiple root panes (as the previous part of this answer suggests), you could first merge the bundles, then load the FXML a single time resulting in a single root pane. 因此,如果是这种情况,则不必先分别加载每个捆绑软件并加载FXML,从而导致多个根窗格(如该答案的上半部分所建议),您可以首先合并捆绑软件,然后再将FXML单个加载时间生成单个根窗格。

FXMLLoader loader = new FXMLLoader(getClass().getResource("main.fxml"));
loader.setResources(merge(bundle1, bundle2));
Parent root = loader.load();

Where merge(bundle1, bundle2) is some function which you develop yourself based upon the answers in the linked questions. 其中merge(bundle1, bundle2)是一些功能,您可以根据链接的问题中的答案merge(bundle1, bundle2)开发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM