22

In some project we can have this situation

enter image description here

How to get programmatically list of supported languages by this app/project? As the result I need string array like this

{ "en", "bg", "bs", "da", "de", "hr", "it", "nl", "pl", "pt", "sk", "sr", "tr" }

Of course I can hardcode it by typing it but I suppose code can and should do it.

And why I need it - I have a separate library that deals with localization, instant change of UI after selecting new language etc. App must tell library which languages it supports. And it's nice just to add new xml for a new language without changing code (updating that hardcoded list).

Dark
  • 864
  • 9
  • 17
  • 1
    "How to get programmatically list of supported languages by this app/project?" -- programmatically send an email to the app's developer asking her what languages are supported. You cannot rely upon the existence of sets of string resources in the APK, as those strings may be supplied by libraries and may not be complete. – CommonsWare May 21 '15 at 13:39
  • 2
    Maybe my question wasn't clear enough - I'm not talking about some "foreign" APKs but my projects :) so I know which languages are supported, I just want to automatize adding of a new language – Dark May 21 '15 at 13:43
  • 4
    You could create a bit of Groovy code, or a full-fledged Gradle plugin, that scans your project for `res/values-*/strings.xml` files, or for other files that have string resources. – CommonsWare May 21 '15 at 13:45
  • Yes it could work. But I suppose there should be some "cleaner" way to get it using Android API, not parsing file names – Dark May 21 '15 at 13:49
  • 4
    "But I suppose there should be some "cleaner" way to get it using Android API" -- no, because, as I wrote originally, what is in your APK has no relevance for your problem, unless you are specifically taking steps to remove strings from your builds. You are not the only programmer who is contributing code to your project, in all likelihood. If you are using third-party libraries, including the Android Support package or Play Services SDK, they will be contributing strings as well. – CommonsWare May 21 '15 at 13:50
  • relevant question : https://stackoverflow.com/questions/11611065/get-the-applications-resources-languages – matan h Apr 14 '22 at 07:29

0 Answers0