@@ -16,8 +16,11 @@ file to a [StringBinding]. This makes it very easy to change the language during
16
16
runtime in a [ JavaFX] application.
17
17
Lib-I18N is written in JavaFX, [ Maven] and [ NetBeans] .
18
18
19
- _ Image:_ Example integration [ App-Yin-Yang]
20
- ![ Integration_App-Yin-Yang_v0.7.0_2018-12-29_20-54.png] [ Integration_App-Yin-Yang_v0.7.0_2018-12-29_20-54 ]
19
+ _ Image:_ Demo integration from Lib-I18N
20
+ ![ Lib-I18N_Demo_v0.8.0_2019-04-27_16-24.png] [ Lib-I18N_Demo_v0.8.0_2019-04-27_16-24 ]
21
+
22
+ The demo shows how easy an application becomes multilingual in four steps :smile : .
23
+ Plz see the section ` Demo ` for more informations.
21
24
22
25
23
26
@@ -36,6 +39,11 @@ Content
36
39
- [ How to use the builder I18NResourceBundleBuilder] ( #HoToUsReBuBu )
37
40
- [ How to use the builder I18NBindingBuilder] ( #HoToUsBiBu )
38
41
- [ How to use the builder I18NMessageBuilder] ( #HoToUsMeBu )
42
+ * [ Demo] ( #Demo )
43
+ - [ Step one: Prepare your application] ( #DePrYoAp )
44
+ - [ Step two: Register the ResourceBundle] ( #DeStTw )
45
+ - [ Step three: Bind the text components] ( #DeStTh )
46
+ - [ Step four: Switch the language during runtime] ( #DeStFo )
39
47
* [ JavaDoc] ( #JavaDoc )
40
48
* [ Download] ( #Download )
41
49
* [ Requirements] ( #Requirements )
@@ -590,6 +598,125 @@ public void lastStepWithArguments() {
590
598
591
599
592
600
601
+ Demo<a name =" Demo " />
602
+ ---
603
+
604
+ The demo applications shows how to integrate the library ` Lib-I18N ` in four simple steps.
605
+
606
+ _ Image:_ Demo application
607
+ ![ Lib-I18N_Demo-English_v0.8.0_2019-04-27_16-14.png] [ Lib-I18N_Demo-English_v0.8.0_2019-04-27_16-14 ]
608
+
609
+ ### Step one: Prepare your application<a name =" DePrYoAp " />
610
+
611
+ First inject the library 'Lib-I18N' into your project.
612
+ Then create for every supported language a .properties file.
613
+
614
+ ``` xml
615
+ <dependencies >
616
+ <dependency >
617
+ <groupId >com.github.naoghuman</groupId >
618
+ <artifactId >lib-i18n</artifactId >
619
+ <version >0.8.0</version >
620
+ </dependency >
621
+ </dependencies >
622
+ ```
623
+
624
+ _ Image:_ Demo .properties files
625
+ ![ Lib-I18N_Demo-properties-files_v0.8.0_2019-04-27_17-33.png] [ Lib-I18N_Demo-properties-files_v0.8.0_2019-04-27_17-33 ]
626
+
627
+
628
+ ### Step two: Register the ResourceBundle<a name =" DeStTw " />
629
+
630
+ Next register the ResourceBundle where ` supportedLocales ` are corresponding to every existing .properties file and ` actualLocale ` is the language which will shown first.
631
+
632
+ ``` java
633
+ public final class DemoI18NStart extends Application {
634
+
635
+ @Override
636
+ public void init () throws Exception {
637
+ I18NResourceBundleBuilder . configure()
638
+ .baseBundleName(" com.github.naoghuman.lib.i18n.demo_i18n" ) // NOI18N
639
+ .supportedLocales(Locale . ENGLISH , Locale . FRENCH , Locale . GERMAN , Locale . ITALIAN )
640
+ .defaultLocale(Locale . ENGLISH )
641
+ .actualLocale(Locale . ENGLISH )
642
+ .build();
643
+ }
644
+ }
645
+ ```
646
+
647
+ ### Step three: Bind the text components<a name =" DeStTh " />
648
+
649
+ In the third step the text components will be bind to the depending key from the ResourceBundle.
650
+
651
+ ``` java
652
+ public final class DemoI18NController extends FXMLController implements Initializable {
653
+
654
+ @FXML private Button bFrench;
655
+ @FXML private Button bGerman;
656
+ @FXML private Button bItalian;
657
+ @FXML private Button bEnglish;
658
+ @FXML private Label lLanguages;
659
+ @FXML private Text tAbout;
660
+ @FXML private Text tFrom;
661
+ @FXML private Text tHello;
662
+ @FXML private Text tLand;
663
+
664
+ @Override
665
+ public void initialize (final URL location , final ResourceBundle resources ) {
666
+ // Menu
667
+ this . bind(lLanguages. textProperty(), " demo.i18n.languages" ); // NOI18N
668
+ this . bind(bFrench. textProperty(), " demo.i18n.language.french" ); // NOI18N
669
+ this . bind(bGerman. textProperty(), " demo.i18n.language.german" ); // NOI18N
670
+ this . bind(bItalian. textProperty(), " demo.i18n.language.italian" ); // NOI18N
671
+ this . bind(bEnglish. textProperty(), " demo.i18n.language.english" ); // NOI18N
672
+
673
+ // Message
674
+ this . bind(tHello. textProperty(), " demo.i18n.greetings" ); // NOI18N
675
+ this . bind(tFrom. textProperty(), " demo.i18n.from" ); // NOI18N
676
+ this . bind(tLand. textProperty(), " demo.i18n.land" ); // NOI18N
677
+ this . bind(tAbout. textProperty(), " demo.i18n.about" ); // NOI18N
678
+ }
679
+
680
+ private void bind (final StringProperty stringProperty , final String key ) {
681
+ final Optional<StringBinding > optionalStringBinding = I18NBindingBuilder . bind(). key(key). build();
682
+ optionalStringBinding. ifPresent(stringBinding - > {
683
+ stringProperty. bind(stringBinding);
684
+ });
685
+ }
686
+ }
687
+ ```
688
+
689
+ ### Step four: Switch the language during runtime<a name =" DeStFo " />
690
+
691
+ And in the last step the user will change the language in the runing application which leads to a change from the ` actualLocale ` which performs then the language update in the gui.
692
+
693
+ ``` java
694
+ public final class DemoI18NController extends FXMLController implements Initializable {
695
+
696
+ public void onActionSwitchToLanguageFrench () {
697
+ if (I18NFacade . getDefault(). getActualLocale(). equals(Locale . FRENCH )) {
698
+ LoggerFacade . getDefault(). debug(this . getClass(), " Shows already the Locale.FRENCH - do nothing." ); // NOI18N
699
+ return ;
700
+ }
701
+
702
+ I18NFacade . getDefault(). setActualLocale(Locale . FRENCH );
703
+ }
704
+
705
+ public void onActionSwitchToLanguageGerman () {
706
+ if (I18NFacade . getDefault(). getActualLocale(). equals(Locale . GERMAN )) {
707
+ LoggerFacade . getDefault(). debug(this . getClass(), " Shows already the Locale.GERMAN - do nothing." ); // NOI18N
708
+ return ;
709
+ }
710
+
711
+ I18NFacade . getDefault(). setActualLocale(Locale . GERMAN );
712
+ }
713
+
714
+ ...
715
+ }
716
+ ```
717
+
718
+
719
+
593
720
JavaDoc<a name =" JavaDoc " />
594
721
---
595
722
@@ -691,7 +818,9 @@ You can reach me under <peter.rogge@yahoo.de>.
691
818
692
819
693
820
[ // ] : # ( Images )
694
- [ Integration_App-Yin-Yang_v0.7.0_2018-12-29_20-54 ] :https://user-images.githubusercontent.com/8161815/50541765-ab6f7680-0bac-11e9-9a55-6111ffa1c70b.png
821
+ [ Lib-I18N_Demo_v0.8.0_2019-04-27_16-24 ] :https://user-images.githubusercontent.com/8161815/56850906-1a659d80-6909-11e9-93f2-a1b099875c2f.png
822
+ [ Lib-I18N_Demo-English_v0.8.0_2019-04-27_16-14 ] :https://user-images.githubusercontent.com/8161815/56850913-29e4e680-6909-11e9-9a87-f519c9b9bf71.png
823
+ [ Lib-I18N_Demo-properties-files_v0.8.0_2019-04-27_17-33 ] :https://user-images.githubusercontent.com/8161815/56851721-b1832300-6912-11e9-9638-bc95ca416c60.png
695
824
[ Lib-I18N_JavaDoc_v0.7.2_2019-04-22_09-39 ] :https://user-images.githubusercontent.com/8161815/56489671-beeb7800-64e2-11e9-8553-803fc8d15dc8.png
696
825
697
826
0 commit comments