Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download Android string resources at build time

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!

like image 597
ChilliBits Avatar asked Sep 12 '25 10:09

ChilliBits


1 Answers

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.

like image 119
ChilliBits Avatar answered Sep 15 '25 00:09

ChilliBits