'How can I use the Android String Translation in a LibGDX Project?
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?
Solution 1:[1]
Three different paths you can take:
Merge your
coremodule code into theandroidmodule and simply don't usecore. 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.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.
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tenfour04 |
