FXGL icon indicating copy to clipboard operation
FXGL copied to clipboard

Getting excetion when setting selected language in LocalizationService

Open hansnf opened this issue 2 years ago • 1 comments

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

hansnf avatar Feb 14 '24 21:02 hansnf

Hi,

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

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

Let me know if it works.

AlmasB avatar Feb 18 '24 11:02 AlmasB

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

hansnf avatar Feb 26 '24 21:02 hansnf