AlmasB / FXGL

Java / JavaFX / Kotlin Game Library (Engine)
http://almasb.github.io/FXGL/
MIT License
4.41k stars 552 forks source link

Localization via .properties #336

Closed AlmasB closed 5 years ago

AlmasB commented 7 years ago

Strings can be stored in a .properties file and loaded as a ResourceBundle with AssetLoader. If two different locales use the same key set (as a normal Java app would), then we can use getString() in code, which would map to system locale file.

Example:

File: en.properties

exit = exit

File: fr.properties

exit = quitter

File: ru.properties

exit = выход

Then in the menu code something like:

Button btnExit = new Button(FXGL.getLocaleString("exit"));

The implementation of getLocaleString() should first read the system locale, then find a pre-defined properties file for that locale and retrieve the property. Probably best to use pre-defined file names from what Java locale property bundle gives us.

AlmasB commented 6 years ago

Foundation done in 0.4.0, now need game_language.properties for in-game text and populate supported language.properties

AlmasB commented 5 years ago

Likely to be used via Local.add(lang, resource map<String, String>).

AlmasB commented 5 years ago

There are now semantically equivalent ways to add localization (supports both engine and game text):

1. getLocalizationService().addLanguageData(new Language("ENGLISH"), Map.of("some.key", "Hello World"));

OR

getLocalizationService().addLanguageData(Language.ENGLISH, Map.of("some.key", "Hello World"));

2. getLocalizationService().addLanguageData(Language.ENGLISH, assetLoader.loadResourceBundle("english.properties"));