fxml 文件中的 FXML 翻译功能
FXML translation feature in fxml file
我在 fxml 中有这个对象(以及其他对象):
<Label text="Birthday">
<font>
<Font size="16.0" />
</font>
</Label>
我也有这个Excel文档:
Birthday Date d'anniversaire День Рождения
它包含生日一词的两个翻译。
我需要能够在下拉列表中的应用程序中选择另一种语言时更改标签的文本。我该怎么做?是否可以在 .fxml
文件中执行?
这是我从文件加载阶段的方式:
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
scene = new Scene(fxmlLoader.load(), 500, 400);
如上评论所述,这只是我过去翻译的一个例子。这不会在 FXML 中进行转换。
FXML 片段 (frmCalendar.fxml)
<Label fx:id="lblTitle" text="Title"/>
控制器片段 Class (CalendarController.java)
if (!Locale.getDefault().getLanguage().equals("en")) {
lblTitle.setText(TranslationManager.translate("en", Locale.getDefault().getLanguage(), lblTitle.getText());
}
TranslationManager.java
的片段
public class TranslationManager {
public static String translate(String langFrom, String langTo, String text){
//Here is where you would read your excel file and return the text in the desired language.
}
}
如果您不熟悉该过程,question about reading excel files 这里有一个很好的例子。
我在 fxml 中有这个对象(以及其他对象):
<Label text="Birthday">
<font>
<Font size="16.0" />
</font>
</Label>
我也有这个Excel文档:
Birthday Date d'anniversaire День Рождения
它包含生日一词的两个翻译。
我需要能够在下拉列表中的应用程序中选择另一种语言时更改标签的文本。我该怎么做?是否可以在 .fxml
文件中执行?
这是我从文件加载阶段的方式:
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
scene = new Scene(fxmlLoader.load(), 500, 400);
如上评论所述,这只是我过去翻译的一个例子。这不会在 FXML 中进行转换。 FXML 片段 (frmCalendar.fxml)
<Label fx:id="lblTitle" text="Title"/>
控制器片段 Class (CalendarController.java)
if (!Locale.getDefault().getLanguage().equals("en")) {
lblTitle.setText(TranslationManager.translate("en", Locale.getDefault().getLanguage(), lblTitle.getText());
}
TranslationManager.java
的片段public class TranslationManager {
public static String translate(String langFrom, String langTo, String text){
//Here is where you would read your excel file and return the text in the desired language.
}
}
如果您不熟悉该过程,question about reading excel files 这里有一个很好的例子。