Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I get the defined string in string xml file in res in libgdx?

I am trying to get a resource string variables in file string.xml in the res folder in the android directory for libgdx from the core java class files.

like image 748
Sam Avatar asked Oct 17 '25 00:10

Sam


1 Answers

If you want to translate for multiple languages i will tell you that the best way to do it is not using the string.xml file from android.

What i did is. Inside the folder Assets in the android project i create a folder with the name String -> Inside this folder i create the string i will use in my app.

String folder

Then to load the string i will use I18NBundle. For example:

I18NBundle languageStrings = I18NBundle.createBundle(Gdx.files.internal("strings/strings"), locale);
String hello = languageString.get("hello");

This will work for Desktop, Android, iOS and GWT. So it better option than using the android res folder.

You can check more of this in the wiki of libgdx Libgdx wiki

like image 64
Yayo Arellano Avatar answered Oct 19 '25 16:10

Yayo Arellano



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!