Home > Net >  How can I use the Android String Translation in a LibGDX Project?
How can I use the Android String Translation in a LibGDX Project?

Time:03-24

I'm trying to use the Android String Resources for an LibGDX Project.

Unfortunately, I can only access the getString()-Method and the R class from the android package.

What can I do to access them from also the core package?

Or is it even better to use another solution for translation files?

CodePudding user response:

Three different paths you can take:

  1. Merge your core module code into the android module and simply don't use core. The downside with doing this is you will lose the ability to easily test on your desktop (it's faster to compile a desktop build for rapidly testing code changes), and you lose the ability to port to other platforms like desktop and iOS.

  2. Use libGDX's localization classes to manage your strings in different languages, instead of Android resources. There are instructions on how to use it here. This is the easiest solution, and it keeps it cross-platform.

  3. Maybe you could write some kind of Gradle task that extracts your String IDs from the generated R class each time you build your Android module, and makes copies of them available in a Java class in your core module, and uses them to retrieve Strings from the XML through some kind of interface. This is the super difficult solution.

  • Related