0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 12:02:16 +02:00

Duplicate CrowdIn Strings: Ignore translated

We only want to check and warn for duplicates in our new strings

Related: 7582
This commit is contained in:
David Allison 2020-11-12 06:17:14 +00:00 committed by Mike Hardy
parent 60b7c8ec1d
commit 4c140c6f24
2 changed files with 20 additions and 2 deletions

View File

@ -112,6 +112,11 @@ public class DuplicateCrowdInStrings extends ResourceXmlDetector {
@Override
public void visitElement(@NotNull XmlContext context, @NotNull Element element) {
// Only check the golden copy - not the translated sources.
if (!"values".equals(context.file.getParentFile().getName())) {
return;
}
NodeList childNodes = element.getChildNodes();
if (childNodes.getLength() > 0) {
if (childNodes.getLength() == 1) {

View File

@ -26,7 +26,7 @@ public class DuplicateCrowdInStringsTest {
/** Easiest test case: Two exact duplicates in the same file */
@Language("XML")
private final String selfInvalid = "<resources>\n" +
private final String mSelfInvalid = "<resources>\n" +
" <string name=\"hello\">a</string>\n" +
" <string name=\"hello2\">a</string>\n" +
"</resources>";
@ -38,9 +38,22 @@ public class DuplicateCrowdInStringsTest {
lint()
.allowMissingSdk()
.allowCompilationErrors()
.files(xml("res/values/string.xml", selfInvalid))
.files(xml("res/values/string.xml", mSelfInvalid))
.issues(DuplicateCrowdInStrings.ISSUE)
.run()
.expectErrorCount(1);
}
@Test
public void invalidStringInNonEnglishPasses() {
// We only want to check the base resource files, not the translated ones -
// translators know if values are equivalent and do not require a comment explaining why.
lint()
.allowMissingSdk()
.allowCompilationErrors()
.files(xml("res/values-af/string.xml", mSelfInvalid))
.issues(DuplicateCrowdInStrings.ISSUE)
.run()
.expectErrorCount(0);
}
}