JavaFX国际化,带有翻译字符串中的变量
我刚刚发现,JavaFX有一个内置的国际化特性! 因为我开始重写我的应用程序的GUI,所以我将使用这个方便的功能。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文件格式
我唯一找不到的是如何将动态值添加到翻译后的字符串中…
例如:
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}.
不,在那种情况下没有必要。