mirror of
https://github.com/revanced/revanced-patches.git
synced 2025-04-29 22:24:27 +02:00
ci: Preprocess strings before pushing to Crowdin (#4383)
This commit is contained in:
parent
d003fd2c37
commit
1172da23ff
2
.github/workflows/pull_strings.yml
vendored
2
.github/workflows/pull_strings.yml
vendored
@ -2,7 +2,7 @@ name: Pull strings
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: "0 */8 * * *"
|
||||
- cron: "0 */6 * * *"
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
|
3
.github/workflows/push_strings.yml
vendored
3
.github/workflows/push_strings.yml
vendored
@ -18,6 +18,9 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Preprocess strings
|
||||
run: ./gradlew clean preprocessCrowdinStrings
|
||||
|
||||
- name: Push strings
|
||||
uses: crowdin/github-action@v2
|
||||
with:
|
||||
|
@ -3,6 +3,6 @@ api_token_env: "CROWDIN_PERSONAL_TOKEN"
|
||||
|
||||
preserve_hierarchy: false
|
||||
files:
|
||||
- source: patches/src/main/resources/addresources/values/strings.xml
|
||||
- source: patches/build/tmp/crowdin/strings.xml
|
||||
translation: patches/src/main/resources/addresources/values-%android_code%/strings.xml
|
||||
skip_untranslated_strings: true
|
||||
|
@ -21,6 +21,22 @@ dependencies {
|
||||
compileOnly(project(":patches:stub"))
|
||||
}
|
||||
|
||||
tasks {
|
||||
register<JavaExec>("preprocessCrowdinStrings") {
|
||||
description = "Preprocess strings for Crowdin push"
|
||||
|
||||
dependsOn(build)
|
||||
|
||||
classpath = sourceSets["main"].runtimeClasspath
|
||||
mainClass.set("app.revanced.util.CrowdinPreprocessorKt")
|
||||
|
||||
args = listOf(
|
||||
"src/main/resources/addresources/values/strings.xml",
|
||||
"build/tmp/crowdin/strings.xml"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
freeCompilerArgs = listOf("-Xcontext-receivers")
|
||||
@ -38,4 +54,4 @@ publishing {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package app.revanced.util
|
||||
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Comments out the non-standard <app> and <patch> tags.
|
||||
*
|
||||
* Previously this was done on Crowdin after pushing.
|
||||
* But Crowdin preprocessing has randomly failed but still used the unmodified
|
||||
* strings.xml file, which effectively deletes all patch strings from Crowdin.
|
||||
*/
|
||||
internal fun main(args: Array<String>) {
|
||||
if (args.size != 2) {
|
||||
throw RuntimeException("Exactly two arguments are required: <input_file> <output_file>")
|
||||
}
|
||||
|
||||
val inputFilePath = args[0]
|
||||
val inputFile = File(inputFilePath)
|
||||
if (!inputFile.exists()) {
|
||||
throw RuntimeException(
|
||||
"Input file not found: $inputFilePath currentDirectory: " + File(".").canonicalPath
|
||||
)
|
||||
}
|
||||
|
||||
// Comment out the non-standard tags. Otherwise Crowdin interprets the file
|
||||
// not as Android but instead a generic xml file where strings are
|
||||
// identified by xml position and not key.
|
||||
val content = inputFile.readText()
|
||||
val tagRegex = """((<app\s+.*>)|(</app>)|(<patch\s+.*>)|(</patch>))""".toRegex()
|
||||
val modifiedContent = content.replace(tagRegex, """<!-- $1 -->""")
|
||||
|
||||
// Write modified content to the output file (creates file if it doesn't exist).
|
||||
val outputFilePath = args[1]
|
||||
val outputFile = File(outputFilePath)
|
||||
outputFile.parentFile?.mkdirs()
|
||||
outputFile.writeText(modifiedContent)
|
||||
|
||||
println("Preprocessed strings.xml to: $outputFilePath")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user