Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaFX国际化,带有翻译字符串中的变量_Java_Javafx_Internationalization - Fatal编程技术网

JavaFX国际化,带有翻译字符串中的变量

JavaFX国际化,带有翻译字符串中的变量,java,javafx,internationalization,Java,Javafx,Internationalization,我刚刚发现,JavaFX有一个内置的国际化特性! 因为我开始重写我的应用程序的GUI,所以我将使用这个方便的功能。 我唯一找不到的是如何将动态值添加到翻译后的字符串中… 例如: chat.message.player\u joined=玩家%s已加入 我希望能够用相应的玩家名称替换%s。 但是由于字符串是通过属性文件加载的,而不是类似于node.setText(String.format(“Player%s joined!”,playerName)) 我不知道该怎么做 我正在使用fxml文件格式

我刚刚发现,JavaFX有一个内置的国际化特性! 因为我开始重写我的应用程序的GUI,所以我将使用这个方便的功能。
我唯一找不到的是如何将动态值添加到翻译后的字符串中…
例如:
chat.message.player\u joined=玩家%s已加入
我希望能够用相应的玩家名称替换%s。
但是由于字符串是通过属性文件加载的,而不是类似于
node.setText(String.format(“Player%s joined!”,playerName))

我不知道该怎么做


我正在使用fxml文件格式化我的windows,顺便说一句,使用
MessageFormat
messageArguments

代码

Label l = new Label();

final Locale currentLocale = new Locale("en", "US");
ResourceBundle bundle = ResourceBundle.getBundle("Bundle", currentLocale);
Object[] messageArguments = {new Integer(5)};

MessageFormat formatter = new MessageFormat("");
formatter.setLocale(currentLocale);

formatter.applyPattern(bundle.getString("TEST_BUNDLE_TEXT"));
l.setText(formatter.format(messageArguments));
TEST_BUNDLE_TEXT=Test text with integer {0}.
资源包

Label l = new Label();

final Locale currentLocale = new Locale("en", "US");
ResourceBundle bundle = ResourceBundle.getBundle("Bundle", currentLocale);
Object[] messageArguments = {new Integer(5)};

MessageFormat formatter = new MessageFormat("");
formatter.setLocale(currentLocale);

formatter.applyPattern(bundle.getString("TEST_BUNDLE_TEXT"));
l.setText(formatter.format(messageArguments));
TEST_BUNDLE_TEXT=Test text with integer {0}.

不,在那种情况下没有必要。