簡體   English   中英

fxml 文件中的 FXML 翻譯功能

[英]FXML translation feature in fxml file

我在 fxml 中有這個 object(等等):

  <Label text="Birthday">
        <font>
          <Font size="16.0" />
        </font>
  </Label>

我也有這個 Excel 文件:

Birthday     Date d'anniversaire     День Рождения

它包含生日這個詞的兩個翻譯。

當在下拉列表中的應用程序中選擇另一種語言時,我需要能夠更改 label 的文本。 我該怎么做? 是否可以在.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"/>

Controller 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.
    }
}

如果您不熟悉該過程,這里有一個關於閱讀 excel 文件的好問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM