Jolly
Jolly

Reputation: 399

How to change language in-game with I18NBundle in libGDX?

I've created a I18NBundle and some .properties files containing the strings. To create the bundle i wrote this:

baseFileHandle = Gdx.files.internal("Language/Lang");

da_DK = new Locale("da", "DK");
en_GB = new Locale("en", "GB");

Lang = I18NBundle.createBundle(baseFileHandle, en_GB);

This works perfectly well, and I can extract the values from the bundle to get my strings, and it also works by using da_DK instead of en_GB when i initialize the bundle.

My proplem is that I want to be able to change the language in game by pressing a button, but I have no idea how to do that.

I've googled the problem, but cant seem to find an answer.

I hope that you understood my problem, and that you can help me :)

Upvotes: 7

Views: 2247

Answers (1)

noone
noone

Reputation: 19776

If you have a look at the code (I18NBundle.setLocale(...), which is a private method) you will see this JavaDoc:

Sets the bundle locale. This method is private because a bundle can't change the locale during its life.

That means, what you want to do is not possible. What you can do of course, is creating a new I18NBundle supplying another Locale to the constructor and basically just replacing the current one. In case you are using an AssetManager to load it, this is also possible, you would just need to unload it and then load it once more with different parameters.

Upvotes: 7

Related Questions