summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xitstool.in37
1 files changed, 33 insertions, 4 deletions
diff --git a/itstool.in b/itstool.in
index 45ff0c0..701f8ca 100755
--- a/itstool.in
+++ b/itstool.in
@@ -476,6 +476,7 @@ class Document (object):
if load_dtd:
ctxt.loadSubset(1)
if keep_entities:
+ ctxt.ctxtUseOptions(libxml2.XML_PARSE_DTDLOAD)
ctxt.replaceEntities(0)
else:
ctxt.replaceEntities(1)
@@ -491,8 +492,17 @@ class Document (object):
elif xml_is_ns_name(child, NS_ITS, 'rules'):
if child.hasNsProp('href', NS_XLINK):
href = child.nsProp('href', NS_XLINK)
- href = os.path.join(os.path.dirname(filename), href)
- hctxt = libxml2.createFileParserCtxt(href)
+ fileref = os.path.join(os.path.dirname(filename), href)
+ if not os.path.exists(fileref):
+ if opts.itspath is not None:
+ for pathdir in opts.itspath:
+ fileref = os.path.join(pathdir, href)
+ if os.path.exists(fileref):
+ break
+ if not os.path.exists(fileref):
+ sys.stderr.write('Error: Could not locate ITS file %s\n' % href)
+ sys.exit(1)
+ hctxt = libxml2.createFileParserCtxt(fileref)
hctxt.replaceEntities(1)
hctxt.parseDocument()
root = hctxt.doc().getRootElement()
@@ -1028,6 +1038,7 @@ class Document (object):
ctxt = libxml2.createDocParserCtxt(blurb)
if self._load_dtd:
ctxt.loadSubset(1)
+ ctxt.ctxtUseOptions(libxml2.XML_PARSE_DTDLOAD)
ctxt.replaceEntities(0)
ctxt.parseDocument()
trnode = ctxt.doc().getRootElement()
@@ -1056,7 +1067,17 @@ class Document (object):
repl = self.get_translated(ph_node, translations, strict=strict, lang=lang)
child.replaceNode(repl)
scan_node(child)
- scan_node(trnode)
+ try:
+ scan_node(trnode)
+ except:
+ if strict:
+ raise
+ else:
+ sys.stderr.write('Warning: Could not merge %stranslation for msgid:\n%s\n' % (
+ (lang + ' ') if lang is not None else '',
+ msgstr.encode('utf-8')))
+ self._xml_err = ''
+ return node
retnode = node.copyNode(2)
for child in xml_child_iter(trnode):
retnode.addChild(child.copyNode(1))
@@ -1419,7 +1440,9 @@ def convert_locale (locale):
if __name__ == '__main__':
options = optparse.OptionParser()
- options.set_usage('\n itstool [OPTIONS] [XMLFILES]\n itstool -m <MOFILE> [OPTIONS] [XMLFILES]')
+ options.set_usage('\n itstool [OPTIONS] [XMLFILES]\n' +
+ ' itstool -m <MOFILE> [OPTIONS] [XMLFILES]\n' +
+ ' itstool -j <XMLFILE> [OPTIONS] [MOFILES]')
options.add_option('-i', '--its',
action='append',
dest='itsfile',
@@ -1448,6 +1471,12 @@ if __name__ == '__main__':
default=None,
metavar='OUT',
help='Output PO files to file OUT or XML files in directory OUT')
+ options.add_option('--path',
+ action='append',
+ dest='itspath',
+ default=None,
+ metavar='PATHS',
+ help='Extra path where ITS files may be found (can specify multiple times)')
options.add_option('-s', '--strict',
action='store_true',
dest='strict',