From b5656aa5dd2432bb00349038a94be386c9e9abdb Mon Sep 17 00:00:00 2001 From: Alan Evans Date: Wed, 5 Aug 2020 10:54:44 -0300 Subject: [PATCH] Exclude non-translatable multiline blocks. --- app/lint.xml | 6 ++++-- app/translations.gradle | 31 ++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/lint.xml b/app/lint.xml index 3dbcef650..805f69b92 100644 --- a/app/lint.xml +++ b/app/lint.xml @@ -11,11 +11,13 @@ - + + + - + diff --git a/app/translations.gradle b/app/translations.gradle index 43b8f510f..a846213cd 100644 --- a/app/translations.gradle +++ b/app/translations.gradle @@ -79,18 +79,39 @@ task excludeNonTranslatables { .toSet() def all = english.collect { it['@name'] }.toSet() def translatable = all - nonTranslatable + def inMultiline = false + def endBlockName = "" allStringsResourceFiles { f -> if (f != englishFile) { def newLines = f.readLines() .collect { line -> - def matcher = line =~ /name="([^"]*)".*<\// - if (matcher.find()) { - def name = matcher.group(1) - if (!line.contains('excludeNonTranslatables') && !translatable.contains(name)) { - return " " + if (!inMultiline) { + def singleLineMatcher = line =~ /name="([^"]*)".*<\// + if (singleLineMatcher.find()) { + def name = singleLineMatcher.group(1) + if (!line.contains('excludeNonTranslatables') && !translatable.contains(name)) { + return " " + } + } else { + def multilineStartMatcher = line =~ /<(.*) .?name="([^"]*)".*/ + if (multilineStartMatcher.find()) { + endBlockName = multilineStartMatcher.group(1) + def name = multilineStartMatcher.group(2) + if (!line.contains('excludeNonTranslatables') && !translatable.contains(name)) { + inMultiline = true; + return " " } } + return line }