diff options
author | Danilo Šegan <danilo@src.gnome.org> | 2006-03-31 23:12:05 +0000 |
---|---|---|
committer | Danilo Šegan <danilo@src.gnome.org> | 2006-03-31 23:12:05 +0000 |
commit | 8f95f231130ca01862a60c96d558cc534c805379 (patch) | |
tree | 38b3d5b126c667fc01bb93a4f29115056457f591 /xml2po | |
parent | 32fd906da9a14bf3bb155642f3da73f7beba6cee (diff) | |
download | gnome-doc-utils-8f95f231130ca01862a60c96d558cc534c805379.tar.gz |
Improve keep-entities stuff even further, add another test case.
Diffstat (limited to 'xml2po')
-rw-r--r-- | xml2po/ChangeLog | 4 | ||||
-rw-r--r-- | xml2po/tests/ChangeLog | 11 | ||||
-rw-r--r-- | xml2po/tests/adjacent-ents.po | 28 | ||||
-rw-r--r-- | xml2po/tests/adjacent-ents.pot | 28 | ||||
-rw-r--r-- | xml2po/tests/adjacent-ents.xml | 11 | ||||
-rw-r--r-- | xml2po/tests/adjacent-ents.xml.out | 11 | ||||
-rwxr-xr-x | xml2po/tests/test.py | 23 | ||||
-rwxr-xr-x | xml2po/xml2po.py | 38 |
8 files changed, 135 insertions, 19 deletions
diff --git a/xml2po/ChangeLog b/xml2po/ChangeLog index efcf568..fc378fb 100644 --- a/xml2po/ChangeLog +++ b/xml2po/ChangeLog @@ -1,3 +1,7 @@ +2006-04-01 Danilo Šegan <danilo@gnome.org> + + * xml2po.py (replaceNodeContentsWithText): Improve fix for #336765. + 2006-03-31 Danilo Šegan <danilo@gnome.org> Fixes bug #317502. diff --git a/xml2po/tests/ChangeLog b/xml2po/tests/ChangeLog index ccb2011..25977aa 100644 --- a/xml2po/tests/ChangeLog +++ b/xml2po/tests/ChangeLog @@ -1,3 +1,14 @@ +2006-04-01 Danilo Šegan <danilo@gnome.org> + + * adjacent-ents.xml, adjacent-ents.xml.out, adjacent-ents.pot, + adjacent-ents.po: + * test.py (SIMPLETESTS): + Added adjacent-ents.xml test-case. + +2006-04-01 Danilo Šegan <danilo@gnome.org> + + * test.py (SIMPLETESTS): Updated framework to support options. + 2006-03-31 Danilo Šegan <danilo@gnome.org> * keepents.xml, keepents.xml.out, keepents.pot, keepents.po, diff --git a/xml2po/tests/adjacent-ents.po b/xml2po/tests/adjacent-ents.po new file mode 100644 index 0000000..037eccf --- /dev/null +++ b/xml2po/tests/adjacent-ents.po @@ -0,0 +1,28 @@ +msgid "" +msgstr "" +"Project-Id-Version: adjacent entities and elements test\n" +"POT-Creation-Date: 2006-04-01 00:02+0200\n" +"PO-Revision-Date: 2006-04-01 01:10+0200\n" +"Last-Translator: Данило\n" +"Language-Team: српски\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: adjacent-ents.xml:8(para) +msgid "&suselinux; &suse-version; Release Notes" +msgstr "&suselinux; &suse-version; Објава издања" + +#: adjacent-ents.xml:9(para) +msgid "<application>SUSE Linux</application> &suse-version; is ..." +msgstr "<application>SUSE Линукс</application> &suse-version; је ..." + +#: adjacent-ents.xml:10(para) +msgid "&suselinux; <application>&suse-version;</application> is ..." +msgstr "&suselinux; <application>&suse-version;</application> је ..." + +#. Put one translator per line, in the form of NAME <EMAIL>, YEAR1, YEAR2. +#: adjacent-ents.xml:0(None) +msgid "translator-credits" +msgstr "" + diff --git a/xml2po/tests/adjacent-ents.pot b/xml2po/tests/adjacent-ents.pot new file mode 100644 index 0000000..71c12ab --- /dev/null +++ b/xml2po/tests/adjacent-ents.pot @@ -0,0 +1,28 @@ +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: \n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" +"Language-Team: LANGUAGE <LL@li.org>\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: adjacent-ents.xml:8(title) +msgid "&suselinux; &suse-version; Release Notes" +msgstr "" + +#: adjacent-ents.xml:9(para) +msgid "<application>SUSE Linux</application> &suse-version; is ..." +msgstr "" + +#: adjacent-ents.xml:10(para) +msgid "&suselinux; <application>&suse-version;</application> is ..." +msgstr "" + +#. Put one translator per line, in the form of NAME <EMAIL>, YEAR1, YEAR2. +#: adjacent-ents.xml:0(None) +msgid "translator-credits" +msgstr "" + diff --git a/xml2po/tests/adjacent-ents.xml b/xml2po/tests/adjacent-ents.xml new file mode 100644 index 0000000..42f292a --- /dev/null +++ b/xml2po/tests/adjacent-ents.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [ +<!ENTITY suse "SUSE"> +<!ENTITY suselinux "&suse; Linux"> +<!ENTITY suse-version "10.1"> +]> +<sect1> + <title><!-- blah --> &suselinux; &suse-version; Release Notes</title> + <para><application>SUSE Linux</application> &suse-version; is ...</para> + <para>&suselinux; <application> &suse-version;</application> is ...</para> +</sect1> diff --git a/xml2po/tests/adjacent-ents.xml.out b/xml2po/tests/adjacent-ents.xml.out new file mode 100644 index 0000000..fb01f26 --- /dev/null +++ b/xml2po/tests/adjacent-ents.xml.out @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [ +<!ENTITY suse "SUSE"> +<!ENTITY suselinux "&suse; Linux"> +<!ENTITY suse-version "10.1"> +]> +<sect1> + <title>&suselinux; &suse-version; Објава издања</title> + <para><application>SUSE Линукс</application> &suse-version; је ...</para> + <para>&suselinux; <application>&suse-version;</application> је ...</para> +</sect1> diff --git a/xml2po/tests/test.py b/xml2po/tests/test.py index 512eed9..c482b6e 100755 --- a/xml2po/tests/test.py +++ b/xml2po/tests/test.py @@ -1,7 +1,15 @@ #!/usr/bin/env python import sys, os -SIMPLETESTS = ['deep-finals.xml', 'deep-nonfinals.xml', 'attribute-entities.xml', 'docbook.xml', 'utf8-original.xml', 'footnotes.xml', 'keepents.xml' ] +SIMPLETESTS = { 'deep-finals.xml' : {}, + 'deep-nonfinals.xml': {}, + 'attribute-entities.xml': {}, + 'docbook.xml' : {}, + 'utf8-original.xml': {}, + 'footnotes.xml': {}, + 'keepents.xml': { "options" : "-k" }, + 'adjacent-ents.xml': { "options" : "-k" }, + } OTHERTESTS = [ ('relnotes', 'test.sh') ] @@ -9,16 +17,23 @@ if len(sys.argv) > 1: input = sys.argv[1] pot = input.replace(".xml", ".pot") po = input.replace(".xml", ".po") + myopts = "" + if len(sys.argv) > 2: + for opt in sys.argv[2:]: + myopts += " " + opt output = input.replace(".xml", ".xml.out") - ret = os.system("../xml2po %s | sed 's/\"POT-Creation-Date: .*$/\"POT-Creation-Date: \\\\n\"/' | diff -u %s -" % (input, pot)) + ret = os.system("../xml2po %s %s | sed 's/\"POT-Creation-Date: .*$/\"POT-Creation-Date: \\\\n\"/' | diff -u %s -" % (myopts, input, pot)) if ret: print "Problem: extraction from '%s'" % (input) - ret = os.system("../xml2po -p %s %s | diff -u %s -" % (po, input, output)) + ret = os.system("../xml2po -p %s %s %s | diff -u %s -" % (po, myopts, input, output)) if ret: print "Problem: merging translation into '%s'" % (input) else: for t in SIMPLETESTS: - if os.system("%s %s" % (sys.argv[0], t)): + if SIMPLETESTS[t].has_key("options"): + myopts = SIMPLETESTS[t]["options"] + else: myopts = "" + if os.system("%s %s %s" % (sys.argv[0], t, myopts)): print "WARNING: Test %s failed." % (t) for t in OTHERTESTS: diff --git a/xml2po/xml2po.py b/xml2po/xml2po.py index 61835cc..ff9f684 100755 --- a/xml2po/xml2po.py +++ b/xml2po/xml2po.py @@ -116,13 +116,17 @@ msgstr "" def normalizeNode(node): + #print >>sys.stderr, "<%s> (%s) [%s]" % (node.name, node.type, node.serialize('utf-8')) if not node: return elif isSpacePreserveNode(node): return elif node.isText(): - if node.isBlankNode() and (not expand_entities and (not node.next or node.next.type!='entity_ref')): - node.setContent('') + if node.isBlankNode(): + if expand_entities or ( not (node.prev and not node.prev.isBlankNode() + and node.next and not node.next.isBlankNode()) ): + #print >>sys.stderr, "BLANK" + node.setContent('') else: node.setContent(re.sub('\s+',' ', node.content)) @@ -213,6 +217,7 @@ def getTranslation(text, spacepreserve = 0): text should be a string to look for, spacepreserve set to 1 when spaces should be preserved. """ + #print >>sys.stderr,"getTranslation('%s')" % (text.encode('utf-8')) text = normalizeString(text, not spacepreserve) if (text.strip() == ''): return text @@ -302,28 +307,26 @@ def getCommentForNode(node): else: return None - def replaceNodeContentsWithText(node,text): """Replaces all subnodes of a node with contents of text treated as XML.""" if node.children: starttag = node.name #startTagForNode(node) endtag = endTagForNode(node) + + # Lets add document DTD so entities are resolved + tmp = '<?xml version="1.0" encoding="utf-8" ?>' try: - # Lets add document DTD so entities are resolved dtd = doc.intSubset() - tmp = '' - # NOTE: We used to get a "Segmentation fault" in libxml2.parseMemory() when we included DTD - # when not expand_entities! - # libxml 2.6.21 is known to work, need to see what's the minimal version. - #if expand_entities: - tmp = dtd.serialize('utf-8') - tmp = tmp + '<%s>%s</%s>' % (starttag, text, endtag) - except: - tmp = '<%s>%s</%s>' % (starttag, text, endtag) + tmp = tmp + dtd.serialize('utf-8') + except libxml2.treeError: + pass + + content = '<%s>%s</%s>' % (starttag, text, endtag) + tmp = tmp + content.encode('utf-8') try: - ctxt = libxml2.createDocParserCtxt(tmp.encode('utf-8')) + ctxt = libxml2.createDocParserCtxt(tmp) ctxt.replaceEntities(0) ctxt.parseDocument() newnode = ctxt.doc() @@ -339,7 +342,12 @@ def replaceNodeContentsWithText(node,text): free.unlinkNode() free = next - node.addChildList(newelem.children) + add = newelem.children + if node: + copy = newelem.copyNodeList() + next = node.next + node.replaceNode(newelem.copyNodeList()) + node.next = next else: # In practice, this happens with tags such as "<para> </para>" (only whitespace in between) pass |