1
0
Fork 0

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.
This commit is contained in:
Florent Rougon 2021-08-04 00:07:55 +02:00
parent acd34fda78
commit b42f543b93

View file

@ -1373,14 +1373,16 @@ class XliffFormatReader:
if sourceText is not None: if sourceText is not None:
raise XliffParseError( raise XliffParseError(
"{file}: several 'source' elements inside the same " "{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) sourceText = self._handleSourceOrTargetNode(subnode, node.tag)
elif subnode.tag == self.qualTagName("target"): elif subnode.tag == self.qualTagName("target"):
if targetText is not None: if targetText is not None:
raise XliffParseError( raise XliffParseError(
"{file}: several 'target' elements inside the same " "{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) targetText = self._handleSourceOrTargetNode(subnode, node.tag)
elif subnode.tag == self.qualTagName("note"): elif subnode.tag == self.qualTagName("note"):
@ -1392,8 +1394,8 @@ class XliffFormatReader:
if sourceText is None: if sourceText is None:
raise XliffParseError( raise XliffParseError(
"{file}: invalid 'trans-unit' element: doesn't contain any " "{file}: invalid 'trans-unit' element ({id}): doesn't contain "
"'source' element".format(file=self.file)) "any 'source' element".format(file=self.file, id=tid))
# The 'else' clause handles two cases: no <target> element, or an empty # The 'else' clause handles two cases: no <target> element, or an empty
# one. # one.
@ -1406,16 +1408,17 @@ class XliffFormatReader:
if self.insidePluralGroup: if self.insidePluralGroup:
if pluralIndex is None: if pluralIndex is None:
raise XliffParseError( raise XliffParseError(
"{file}: invalid plural group: the id attribute value for " "{file}: invalid plural group for '{id}': the id attribute "
"each form must end with the form's plural index inside " "value for each form must end with the form's plural index "
"brackets (an integer)".format(file=self.file)) "inside brackets (an integer)".format(
file=self.file, id=tid))
# Related plural forms will be merged into one TranslationUnit when # Related plural forms will be merged into one TranslationUnit when
# the containing <group restype="x-gettext-plurals"> ends. # the containing <group restype="x-gettext-plurals"> ends.
self.pluralGroupContents.append((tid, pluralIndex, translUnit)) self.pluralGroupContents.append((tid, pluralIndex, translUnit))
elif tid.cat not in self.transl: elif tid.cat not in self.transl:
raise XliffParseError( raise XliffParseError(
"{file}: unknown category: '{cat}'" "{file}: unknown category '{cat}' for '{id}'"
.format(file=self.file, cat=tid.cat)) .format(file=self.file, cat=tid.cat, id=tid))
# Source text empty + inside an x-gettext-msgctxt -> context dev comment # Source text empty + inside an x-gettext-msgctxt -> context dev comment
# (this is how Qt Linguist works) # (this is how Qt Linguist works)
elif (not sourceText and elif (not sourceText and