For Android application projects that accept user-submitted translations, the number of supported languages may be large and growing. When new languages are added, developers need to manually update resConfig
(1) and language array xml/class (2). Manual means there could be human error.
(1) resConfig
limits the final packaged resources. Libraries may carry languages resources which the language is not supported by the application itself. Set resConfig
could reduce apk size.
(2) If the application has a "choose language" feature, there must be an array of supported languages (could be as an Android resource XML or a Java class).
This plugin collect locales from values-
folders, set resConfig
, generate language array xml/class.
Replace all the <version>
below with the version shows here.
-
Add gradle plugin
// "old way" buildscript { repositories { mavenCentral() } dependencies { classpath 'dev.rikka.tools.autoresconfig:gradle-plugin:<version>' } }
// "new way" plugins { id 'dev.rikka.tools.autoresconfig' version '<version>' }
-
Use the plugin in Android application module
plugins { id('dev.rikka.tools.autoresconfig') }
-
Config in Android application module
autoResConfig { generateClass = true generatedClassFullName = "rikka.autoresconfig.Locales" generateRes = true generatedResPrefix = null generatedArrayFirstItem = "SYSTEM" // Generate Android 13 localeConfig xml // see https://developer.android.com/about/versions/13/features/app-languages#use-localeconfig generateLocaleConfig = true }