From b42f543b93dd8d109c87651472972d2ee0163e8f Mon Sep 17 00:00:00 2001 From: Florent Rougon Date: Wed, 4 Aug 2021 00:07:55 +0200 Subject: [PATCH] i18n.py: print the problematic 'trans-unit' id when aborting It's much easier to locate an error in a .XLF file when one has the id of the 'trans-unit' element that causes the problem. --- python3-flightgear/flightgear/meta/i18n.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/python3-flightgear/flightgear/meta/i18n.py b/python3-flightgear/flightgear/meta/i18n.py index 859d096..c0b53c5 100644 --- a/python3-flightgear/flightgear/meta/i18n.py +++ b/python3-flightgear/flightgear/meta/i18n.py @@ -1373,14 +1373,16 @@ class XliffFormatReader: if sourceText is not None: raise XliffParseError( "{file}: several 'source' elements inside the same " - "'trans-unit' element".format(file=self.file)) + "'trans-unit' element ({id})".format( + file=self.file, id=tid)) sourceText = self._handleSourceOrTargetNode(subnode, node.tag) elif subnode.tag == self.qualTagName("target"): if targetText is not None: raise XliffParseError( "{file}: several 'target' elements inside the same " - "'trans-unit' element".format(file=self.file)) + "'trans-unit' element ({id})".format( + file=self.file, id=tid)) targetText = self._handleSourceOrTargetNode(subnode, node.tag) elif subnode.tag == self.qualTagName("note"): @@ -1392,8 +1394,8 @@ class XliffFormatReader: if sourceText is None: raise XliffParseError( - "{file}: invalid 'trans-unit' element: doesn't contain any " - "'source' element".format(file=self.file)) + "{file}: invalid 'trans-unit' element ({id}): doesn't contain " + "any 'source' element".format(file=self.file, id=tid)) # The 'else' clause handles two cases: no element, or an empty # one. @@ -1406,16 +1408,17 @@ class XliffFormatReader: if self.insidePluralGroup: if pluralIndex is None: raise XliffParseError( - "{file}: invalid plural group: the id attribute value for " - "each form must end with the form's plural index inside " - "brackets (an integer)".format(file=self.file)) + "{file}: invalid plural group for '{id}': the id attribute " + "value for each form must end with the form's plural index " + "inside brackets (an integer)".format( + file=self.file, id=tid)) # Related plural forms will be merged into one TranslationUnit when # the containing ends. self.pluralGroupContents.append((tid, pluralIndex, translUnit)) elif tid.cat not in self.transl: raise XliffParseError( - "{file}: unknown category: '{cat}'" - .format(file=self.file, cat=tid.cat)) + "{file}: unknown category '{cat}' for '{id}'" + .format(file=self.file, cat=tid.cat, id=tid)) # Source text empty + inside an x-gettext-msgctxt -> context dev comment # (this is how Qt Linguist works) elif (not sourceText and