Created
March 20, 2017 08:29
-
-
Save engincancan/191f3864dba3302217a08d6f1f582af8 to your computer and use it in GitHub Desktop.
List Of Supported Languages for Gradle (Android)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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