Tuesday, February 24, 2015

Java: Locale p1

In this tutorial we will create JavaFX app that uses selected Locale to pull i18n (Internationalization) text.


Note:

  • round buttons
  • selected county name
  • text in different character set
  • money notation depending on selected country





Step : create a new IntelliJ Module

  • Module name DisplayLocale
  • create packages as shown in the picture below
  • find country flags icons about 64x64x
  • get some translation texts

Step: Create your translation .profile files

Example Australian English file

morning_greeting=G'day Mate!evening_greeting=G'evening Mate!


Step: Create class DisplayLocaleMain extends Application

Note:
  • import java.util.*
  • import javafx.*
  • extends Application -- JavaFX Application
  • implements Initializable -- automatic injection of Locale 
  • main method
  • @FXML - annotation
  • @override start method
  • css/buttons.css





Note: 

  • @Overrite initialize method
  • Currency.getInstance(bundle.getLocale());
  • NumberFormat.getCurrencyInstance(bundle.getLocale());

Note:
  • FXMLLoader fxmlLoader
  • ResourceBundle.getBundle("bundles.Language", locale, new UTF8Control());
  • fxmlLoader.setResources(languageBundle);
  • getResource("views/TranslatedPhrasesPane.fxml");
  • Pane pane = (BorderPane) fxmlLoader.load(url.openStream()); stage.getScene().getRoot()).getChildren().get(1); LanguageButtonEvent implements EventHandler
  • @Override handle method
  • LocaleBuilder.byLanguageCode(button.getId());







see next part