Skip to content

Instantly share code, notes, and snippets.

@engincancan
Created March 20, 2017 08:29
Show Gist options
  • Save engincancan/191f3864dba3302217a08d6f1f582af8 to your computer and use it in GitHub Desktop.
Save engincancan/191f3864dba3302217a08d6f1f582af8 to your computer and use it in GitHub Desktop.
List Of Supported Languages for Gradle (Android)
task buildTranslationArray << {
def foundLocales = new StringBuilder()
foundLocales.append("new String[]{")
fileTree(dir: 'src', includes: [ '**/*.xml'], exclude: '**/*test*/**').visit { FileVisitDetails details ->
def path = details.file.path;
if (path.endsWith("strings.xml")) {
def languageCode = path.substring(path.indexOf("values"), path.length()).replaceAll('values-','').replace("\\strings.xml", "")
// def languageCode = details.file.parent.tokenize('/').last().replaceAll('values-','').replaceAll('-r','-')
languageCode = (languageCode == "values") ? "tr" : languageCode;
foundLocales.append("\"").append(languageCode).append("\"").append(",")
}
}
foundLocales.append("}")
//Don't forget to remove the trailing comma
def foundLocalesString = foundLocales.toString().replaceAll(',}', '}')
android.defaultConfig.buildConfigField "String[]", "TRANSLATION_ARRAY", foundLocalesString
}
preBuild.dependsOn buildTranslationArray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment