forked from qt-creator/qt-creator
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 <alessandro.portale@qt.io>
This commit is contained in:
@@ -12,6 +12,7 @@ import argparse
|
|||||||
import pathlib
|
import pathlib
|
||||||
import sys
|
import sys
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from enum import Enum, auto
|
||||||
|
|
||||||
def rewriteLines(input, scrubbedContext, tsFilePath):
|
def rewriteLines(input, scrubbedContext, tsFilePath):
|
||||||
result = []
|
result = []
|
||||||
@@ -94,19 +95,46 @@ def findDistinctDuplicates(input, scrubbedContext, tsFilePath):
|
|||||||
continue
|
continue
|
||||||
if inContext:
|
if inContext:
|
||||||
sourceXml = []
|
sourceXml = []
|
||||||
lineNr = inputLineNr
|
|
||||||
for sourceLine in lineIter: # <source>..</source> (possibly multi-line)
|
|
||||||
inputLineNr += 1
|
|
||||||
sourceXml.append(sourceLine)
|
|
||||||
if sourceLine.count(r"</source>") == 1:
|
|
||||||
break
|
|
||||||
sourceXmlHash = hash(str(sourceXml))
|
|
||||||
translationXml = []
|
translationXml = []
|
||||||
for translationLine in lineIter: # <translation>..</translation> (possibly multi-line)
|
lineNr = inputLineNr
|
||||||
|
|
||||||
|
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
|
inputLineNr += 1
|
||||||
translationXml.append(translationLine)
|
if messageLine.count(r"<location") == 1:
|
||||||
if translationLine.count(r"</translation>") == 1:
|
pos = Position.LOCATION
|
||||||
|
elif messageLine.count(r"<source") == 1:
|
||||||
|
pos = Position.SOURCE
|
||||||
|
elif messageLine.count(r"<comment") == 1:
|
||||||
|
pos = Position.COMMENT
|
||||||
|
elif messageLine.count(r"<extracomment") == 1:
|
||||||
|
pos = Position.EXTRACOMMENT
|
||||||
|
elif messageLine.count(r"<translatorcomment") == 1:
|
||||||
|
pos = Position.TRANSLATORCOMMENT
|
||||||
|
elif messageLine.count(r"<translation") == 1:
|
||||||
|
pos = Position.TRANSLATION
|
||||||
|
elif messageLine.count(r"</message>") == 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
|
break
|
||||||
|
|
||||||
|
sourceXmlHash = hash(str(sourceXml))
|
||||||
translation = Translation(lineNr, translationXml)
|
translation = Translation(lineNr, translationXml)
|
||||||
if sourceXmlHash in messages:
|
if sourceXmlHash in messages:
|
||||||
messages[sourceXmlHash].translations.append(translation)
|
messages[sourceXmlHash].translations.append(translation)
|
||||||
@@ -117,6 +145,7 @@ def findDistinctDuplicates(input, scrubbedContext, tsFilePath):
|
|||||||
source = messages[sourceId]
|
source = messages[sourceId]
|
||||||
translationsCount = len(source.translations)
|
translationsCount = len(source.translations)
|
||||||
if translationsCount > 1:
|
if translationsCount > 1:
|
||||||
|
print (f"\n==========================================")
|
||||||
print (f"\n{translationsCount} duplicates for source:")
|
print (f"\n{translationsCount} duplicates for source:")
|
||||||
for sourceXmlLine in source.sourceXml:
|
for sourceXmlLine in source.sourceXml:
|
||||||
print (sourceXmlLine.rstrip())
|
print (sourceXmlLine.rstrip())
|
||||||
|
|||||||
Reference in New Issue
Block a user