Translate tasks.
parent
e4406621ed
commit
840997cb7d
14
build.gradle
14
build.gradle
|
@ -23,6 +23,7 @@ buildscript {
|
|||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'androidx.navigation.safeargs'
|
||||
apply plugin: 'witness'
|
||||
apply from: 'translations.gradle'
|
||||
apply from: 'witness-verifications.gradle'
|
||||
|
||||
repositories {
|
||||
|
@ -431,19 +432,6 @@ def getLastCommitTimestamp() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Discovers supported languages listed as under the res/values- directory.
|
||||
*/
|
||||
static def autoResConfig() {
|
||||
def files = new ArrayList<String>()
|
||||
def root = new File('res')
|
||||
root.eachFile { f -> files.add(f.name) }
|
||||
['en'] + files.collect { f -> f =~ /^values-([a-z]{2}(-r[A-Z]{2})?)$/ }
|
||||
.findAll { matcher -> matcher.find() }
|
||||
.collect { matcher -> matcher.group(1) }
|
||||
.sort()
|
||||
}
|
||||
|
||||
task qa {
|
||||
group 'Verification'
|
||||
description 'Quality Assurance. Run before pushing.'
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
import groovy.io.FileType
|
||||
import groovy.transform.stc.ClosureParams
|
||||
import groovy.transform.stc.SimpleType
|
||||
|
||||
ext {
|
||||
autoResConfig = this.&autoResConfig
|
||||
}
|
||||
|
||||
def allStringsResourceFiles(@ClosureParams(value = SimpleType.class, options = ['java.io.File']) Closure c) {
|
||||
file('res').eachFileRecurse(FileType.FILES) { f ->
|
||||
if (f.name == 'strings.xml') {
|
||||
c(f)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Discovers supported languages listed as under the res/values- directory.
|
||||
*/
|
||||
def autoResConfig() {
|
||||
def files = []
|
||||
allStringsResourceFiles { f ->
|
||||
files.add(f.parentFile.name)
|
||||
}
|
||||
['en'] + files.collect { f -> f =~ /^values-([a-z]{2}(-r[A-Z]{2})?)$/ }
|
||||
.findAll { matcher -> matcher.find() }
|
||||
.collect { matcher -> matcher.group(1) }
|
||||
.sort()
|
||||
}
|
||||
|
||||
task pullTranslations(type: Exec) {
|
||||
group 'Translate'
|
||||
description 'Pull translations, requires transifex client and api key.'
|
||||
commandLine 'tx', 'pull', '-a', '--minimum-perc=80', '--force'
|
||||
}
|
||||
|
||||
task replaceEllipsis {
|
||||
group 'Translate'
|
||||
description 'Process strings for ellipsis characters.'
|
||||
doLast {
|
||||
allStringsResourceFiles { f ->
|
||||
def before = f.text
|
||||
def after = f.text.replace('...', '…')
|
||||
if (before != after) {
|
||||
f.text = after
|
||||
logger.info("$f.parentFile.name/$f.name...updated")
|
||||
}
|
||||
}
|
||||
}
|
||||
mustRunAfter pullTranslations
|
||||
}
|
||||
|
||||
task cleanApostropheErrors {
|
||||
group 'Translate'
|
||||
description 'Fix transifex apostrophe string errors.'
|
||||
doLast {
|
||||
allStringsResourceFiles { f ->
|
||||
def before = f.text
|
||||
def after = before.replaceAll(/([^\\=08])(')/,'$1\\\\\'')
|
||||
if (before != after) {
|
||||
f.text = after
|
||||
logger.info("$f.parentFile.name/$f.name...updated")
|
||||
}
|
||||
}
|
||||
}
|
||||
mustRunAfter replaceEllipsis
|
||||
}
|
||||
|
||||
task translate {
|
||||
group 'Translate'
|
||||
description 'Pull translations and post-process for ellipsis and apostrophes.'
|
||||
dependsOn pullTranslations, replaceEllipsis, cleanApostropheErrors
|
||||
}
|
Loading…
Reference in New Issue