Skip to content
This repository was archived by the owner on Jun 11, 2023. It is now read-only.

Commit f0e464a

Browse files
committed
#87 [doc] Add new section 'Demo'.
1 parent 3d823be commit f0e464a

File tree

4 files changed

+161
-10
lines changed

4 files changed

+161
-10
lines changed

README.md

Lines changed: 132 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ file to a [StringBinding]. This makes it very easy to change the language during
1616
runtime in a [JavaFX] application.
1717
Lib-I18N is written in JavaFX, [Maven] and [NetBeans].
1818

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.
2124

2225

2326

@@ -36,6 +39,11 @@ Content
3639
- [How to use the builder I18NResourceBundleBuilder](#HoToUsReBuBu)
3740
- [How to use the builder I18NBindingBuilder](#HoToUsBiBu)
3841
- [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)
3947
* [JavaDoc](#JavaDoc)
4048
* [Download](#Download)
4149
* [Requirements](#Requirements)
@@ -590,6 +598,125 @@ public void lastStepWithArguments() {
590598

591599

592600

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+
593720
JavaDoc<a name="JavaDoc" />
594721
---
595722

@@ -691,7 +818,9 @@ You can reach me under <peter.rogge@yahoo.de>.
691818

692819

693820
[//]: # (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
695824
[Lib-I18N_JavaDoc_v0.7.2_2019-04-22_09-39]:https://user-images.githubusercontent.com/8161815/56489671-beeb7800-64e2-11e9-8553-803fc8d15dc8.png
696825

697826

release/Release_v0.8.0_2019-04-dd_HH-mm.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Lib-I18N is written in JavaFX, [Maven] and [NetBeans].
3535

3636

3737
#### Documentation
38+
#87 [doc] Add new section 'Demo'.
3839
#85 [doc] Switch the two sections 'Examples' and 'Features.
3940

4041

src/test/java/com/github/naoghuman/lib/i18n/DemoI18NController.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ public final class DemoI18NController extends FXMLController implements Initiali
5353
@Override
5454
public void initialize(final URL location, final ResourceBundle resources) {
5555
LoggerFacade.getDefault().info(this.getClass(), "DemoI18NController#initialize(URL, ResourceBundle)"); // NOI18N
56-
56+
57+
/**
58+
* Step three:
59+
* - Bind the text components to the depending key from the ResourceBundle.
60+
*/
5761
// Menu
5862
this.bind(lLanguages.textProperty(), "demo.i18n.languages"); // NOI18N
5963
this.bind(bFrench.textProperty(), "demo.i18n.language.french"); // NOI18N
@@ -78,11 +82,16 @@ private void bind(final StringProperty stringProperty, final String key) {
7882
});
7983
}
8084

85+
/**
86+
* Step four:
87+
* - Change the 'actualLocale' depending from the user chooses...
88+
* - which will do then the magic :) .
89+
*/
8190
public void onActionSwitchToLanguageFrench() {
8291
LoggerFacade.getDefault().debug(this.getClass(), "DemoI18NController#onActionSwitchToLanguageFrench()"); // NOI18N
8392

8493
if (I18NFacade.getDefault().getActualLocale().equals(Locale.FRENCH)) {
85-
LoggerFacade.getDefault().debug(this.getClass(), "Shows already Locale.FRENCH - do nothing."); // NOI18N
94+
LoggerFacade.getDefault().debug(this.getClass(), "Shows already the Locale.FRENCH - do nothing."); // NOI18N
8695
return;
8796
}
8897

@@ -93,7 +102,7 @@ public void onActionSwitchToLanguageGerman() {
93102
LoggerFacade.getDefault().debug(this.getClass(), "DemoI18NController#onActionSwitchToLanguageGerman()"); // NOI18N
94103

95104
if (I18NFacade.getDefault().getActualLocale().equals(Locale.GERMAN)) {
96-
LoggerFacade.getDefault().debug(this.getClass(), "Shows already Locale.GERMAN - do nothing."); // NOI18N
105+
LoggerFacade.getDefault().debug(this.getClass(), "Shows already the Locale.GERMAN - do nothing."); // NOI18N
97106
return;
98107
}
99108

@@ -104,7 +113,7 @@ public void onActionSwitchToLanguageItalian() {
104113
LoggerFacade.getDefault().debug(this.getClass(), "DemoI18NController#onActionSwitchToLanguageItalian()"); // NOI18N
105114

106115
if (I18NFacade.getDefault().getActualLocale().equals(Locale.ITALIAN)) {
107-
LoggerFacade.getDefault().debug(this.getClass(), "Shows already Locale.ITALIAN - do nothing."); // NOI18N
116+
LoggerFacade.getDefault().debug(this.getClass(), "Shows already the Locale.ITALIAN - do nothing."); // NOI18N
108117
return;
109118
}
110119

@@ -115,7 +124,7 @@ public void onActionSwitchToLanguageEnglish() {
115124
LoggerFacade.getDefault().debug(this.getClass(), "DemoI18NController#onActionSwitchToLanguageEnglish()"); // NOI18N
116125

117126
if (I18NFacade.getDefault().getActualLocale().equals(Locale.ENGLISH)) {
118-
LoggerFacade.getDefault().debug(this.getClass(), "Shows already Locale.ENGLISH - do nothing."); // NOI18N
127+
LoggerFacade.getDefault().debug(this.getClass(), "Shows already the Locale.ENGLISH - do nothing."); // NOI18N
119128
return;
120129
}
121130

src/test/java/com/github/naoghuman/lib/i18n/DemoI18NStart.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public final class DemoI18NStart extends Application {
3636
/**
3737
*
3838
* @param args
39-
* @since 0.3.0-PRERELEASE
40-
* @version 0.3.0-PRERELEASE
39+
* @since 0.8.0
40+
* @version 0.8.0
4141
* @author Naoghuman
4242
*/
4343
public static void main(String[] args) {
@@ -50,6 +50,18 @@ public void init() throws Exception {
5050

5151
LoggerFacade.getDefault().info(this.getClass(), "DemoI18NStart#init()"); // NOI18N
5252

53+
/**
54+
* Step one:
55+
* - Inject the library 'Lib-I18N' into your project.
56+
* - Create for every supported language a .properties file.
57+
*/
58+
59+
/**
60+
* Step two:
61+
* - Register the ResourceBundle
62+
* - where 'supportedLocales' are corresponding to every .properties file
63+
* - and 'actualLocale' is the language which will shown first.
64+
*/
5365
I18NResourceBundleBuilder.configure()
5466
.baseBundleName("com.github.naoghuman.lib.i18n.demo_i18n") // NOI18N
5567
.supportedLocales(Locale.ENGLISH, Locale.FRENCH, Locale.GERMAN, Locale.ITALIAN)

0 commit comments

Comments
 (0)