From bbd64a2c94262d4595ea2aa7dfcf71a08a9eca2d Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Mon, 26 Sep 2022 15:09:59 +0200 Subject: Improve scripts/scrubts.py List the same duplicates that lrelease shows. But better: all occurrences with full filename:linenumber. Change-Id: If0cf38183dbdb4118f2152e1ae86ec92bf0ae1cc Reviewed-by: Alessandro Portale --- scripts/scrubts.py | 51 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/scripts/scrubts.py b/scripts/scrubts.py index a31ef1109ab..9a863970b67 100644 --- a/scripts/scrubts.py +++ b/scripts/scrubts.py @@ -12,6 +12,7 @@ import argparse import pathlib import sys from dataclasses import dataclass +from enum import Enum, auto def rewriteLines(input, scrubbedContext, tsFilePath): result = [] @@ -94,19 +95,46 @@ def findDistinctDuplicates(input, scrubbedContext, tsFilePath): continue if inContext: sourceXml = [] + translationXml = [] lineNr = inputLineNr - for sourceLine in lineIter: # .. (possibly multi-line) + + class Position(Enum): + MESSAGESTART = auto() + LOCATION = auto() + SOURCE = auto() + COMMENT = auto() + EXTRACOMMENT = auto() + TRANSLATORCOMMENT = auto() + TRANSLATION = auto() + MESSAGEOVER = auto() + + pos = Position.MESSAGESTART + + for messageLine in lineIter: inputLineNr += 1 - sourceXml.append(sourceLine) - if sourceLine.count(r"") == 1: + if messageLine.count(r"") == 1: + pos = Position.MESSAGEOVER + + if pos == Position.SOURCE or pos == Position.COMMENT: + sourceXml.append(messageLine) + elif pos == Position.TRANSLATION or pos == Position.EXTRACOMMENT or pos == Position.TRANSLATORCOMMENT: + translationXml.append(messageLine) + elif pos == Position.MESSAGEOVER: break + sourceXmlHash = hash(str(sourceXml)) - translationXml = [] - for translationLine in lineIter: # .. (possibly multi-line) - inputLineNr += 1 - translationXml.append(translationLine) - if translationLine.count(r"") == 1: - break translation = Translation(lineNr, translationXml) if sourceXmlHash in messages: messages[sourceXmlHash].translations.append(translation) @@ -117,13 +145,14 @@ def findDistinctDuplicates(input, scrubbedContext, tsFilePath): source = messages[sourceId] translationsCount = len(source.translations) if translationsCount > 1: + print (f"\n==========================================") print (f"\n{translationsCount} duplicates for source:") for sourceXmlLine in source.sourceXml: - print (sourceXmlLine.rstrip()) + print (sourceXmlLine.rstrip()) for translation in source.translations: print (f"\n{tsFilePath}:{translation.lineNr}") for translationXmlLine in translation.translationXml: - print (translationXmlLine.rstrip()) + print (translationXmlLine.rstrip()) def processTsFile(tsFilePath, scrubbedContext): -- cgit v1.2.3