AlmasB / FXGL

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

Getting excetion when setting selected language in LocalizationService #1344

Closed hansnf closed 9 months ago

hansnf commented 9 months ago

Hello,

I have some using setting the language of the LocalizationService. Whe adding the following method to the class LocalizationSample:

    @Override
    protected void onPreInit() {
        getLocalizationService().addLanguageData(Language.ENGLISH, ResourceBundle.getBundle("assets.texts.texts", Locale.ENGLISH));
        getLocalizationService().setSelectedLanguage(Language.ENGLISH);  
    }  

an exception is thrown:

java.lang.RuntimeException: A bound value cannot be set.
    at javafx.base/javafx.beans.property.ObjectPropertyBase.set(ObjectPropertyBase.java:143)
    at javafx.base/javafx.beans.property.ObjectProperty.setValue(ObjectProperty.java:78)
    at com.almasb.fxgl.core@17/com.almasb.fxgl.localization.LocalizationService.setSelectedLanguage(LocalizationService.kt:37)

I am facing the same issue when trying to change the language from other points in the code. How can the language be changed properly?

Thanks

AlmasB commented 9 months ago

Hi,

all runtime changes normally go through getSettings(). Try this:

getSettings().getLanguage().setValue(...);

Let me know if it works.

hansnf commented 9 months ago

Yes thanks it did. This, however, raised another question I will ask in another issue