4

I work on an app, where we have the different translations of the strings.xml file online to crowdsource translations. The translation tool offers an API for accessing the xml files per URL.

e.g.: https://localise.biz/api/export/locale/en.xml?format=android&key=7qUo-LUKd4VIHSwRYB5005T7QQbaFCGw

Is it possible to download and include those files when the gradle build starts?

Looking forward to your answers!

ChilliBits
  • 135
  • 1
  • 9
  • I think you need to create a custom task to first download files (check https://stackoverflow.com/a/17124244) and then call the build task to build the project. – IamAshKS Dec 15 '19 at 03:36
  • If it doesn't work, try using a download plugin for Gradle. There are abundant such plugins: https://plugins.gradle.org/search?term=Download – IamAshKS Dec 15 '19 at 03:59

1 Answers1

3

IamAshKS served me the answer. I solved it like this:

task downloadTranslations {
   group 'pre-build tasks'
   description 'Downloads all translation files when building the app.'

   ext.apiKey = '7qUo-LUKd4VIHSwRYB5005T7QQbaFCGw'

   //English
   doLast {
      def f = new File("${project.projectDir}/src/main/res/values/strings.xml")
      new URL("https://localise.biz/api/export/locale/en.xml?format=android&key=${apiKey}").withInputStream{ i -> f.withOutputStream{ it << i }}
   }
}

Thanks a lot for your help! Now, I only have to get it running before the actual build.

ChilliBits
  • 135
  • 1
  • 9