android - 在构建时下载 Android 字符串资源
问题描述
我在一个应用程序上工作,在该应用程序中,我们将在线的 strings.xml 文件翻译成众包翻译。翻译工具提供了一个 API,用于访问每个 URL 的 xml 文件。
例如:https://localise.biz/api/export/locale/en.xml?format=android&key=7qUo-LUKd4VIHSwRYB5005T7QQbaFCGw
gradle构建开始时是否可以下载并包含这些文件?
期待您的回答!
解决方案
IamAshKS 为我提供了答案。我是这样解决的:
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 }}
}
}
非常感谢你的帮助!现在,我只需要在实际构建之前运行它。
推荐阅读
- java - 在 ImageView 之外触摸时,Android 应用程序崩溃
- javascript - 从 TypeScript 编译为 JavaScript 后,构造函数名称始终为“Object”
- java - 使用带有转义字符的正则表达式进行 Java 字符串拆分
- css - codeigniter中的自定义字体url
- ssl - 没有'Access-Control-Allow-Origin'标头存在tomcat
- json - Ajax 调用总是从控制器 Magento 2 错误返回
- python - Python for 循环保持在 0
- javascript - 网页是否可以在不需要服务器调用的情况下从另一个文件动态插入数据
- internationalization - 如何在 Aurelia 下的控制台消息上应用 i18n
- javascript - 提交按钮获取对象jquery中的复选框输入