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


As an Amazon Associate I earn from qualifying purchases.

My favorite quotations..


“A man should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.”  by Robert A. Heinlein

"We are but habits and memories we chose to carry along." ~ Uki D. Lucas


Popular Recent Articles