summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShaun McCance <shaunm@gnome.org>2012-09-20 18:37:44 -0400
committerShaun McCance <shaunm@gnome.org>2012-09-20 18:37:44 -0400
commit5040a328ba73ec3dd119f013b9a12a2fdc99a6b9 (patch)
tree4e805c6b2ba28a68c38eeaeb100a3515186c8056
parent7ee29a46d229bde60c86703730b24d5ac49a1e75 (diff)
downloaditstool-5040a328ba73ec3dd119f013b9a12a2fdc99a6b9.tar.gz
Support namespace prefixes on elements
-rwxr-xr-xitstool.in10
-rw-r--r--tests/IT-prefixes-1.ll.po36
-rw-r--r--tests/IT-prefixes-1.ll.xml16
-rw-r--r--tests/IT-prefixes-1.pot36
-rw-r--r--tests/IT-prefixes-1.xml19
-rw-r--r--tests/run_tests.py3
6 files changed, 118 insertions, 2 deletions
diff --git a/itstool.in b/itstool.in
index 3a21aaf..ed9d12f 100755
--- a/itstool.in
+++ b/itstool.in
@@ -208,7 +208,10 @@ class Message (object):
def add_start_tag (self, node):
if len(self._message) == 0 or not(isinstance(self._message[-1], basestring)):
self._message.append('')
- self._message[-1] += ('<%s' % node.name)
+ if node.ns() is not None and node.ns().name is not None:
+ self._message[-1] += ('<%s:%s' % (node.ns().name, node.name))
+ else:
+ self._message[-1] += ('<%s' % node.name)
if node.properties is not None:
for prop in node.properties:
if prop.type == 'attribute':
@@ -229,7 +232,10 @@ class Message (object):
if node.children is not None:
if len(self._message) == 0 or not(isinstance(self._message[-1], basestring)):
self._message.append('')
- self._message[-1] += (u'</%s>' % unicode(node.name, 'utf-8'))
+ if node.ns() is not None and node.ns().name is not None:
+ self._message[-1] += ('</%s:%s>' % (node.ns().name, node.name))
+ else:
+ self._message[-1] += ('</%s>' % node.name)
def is_empty (self):
return self._empty
diff --git a/tests/IT-prefixes-1.ll.po b/tests/IT-prefixes-1.ll.po
new file mode 100644
index 0000000..b73a067
--- /dev/null
+++ b/tests/IT-prefixes-1.ll.po
@@ -0,0 +1,36 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"POT-Creation-Date: 2012-09-20 18:22-0400\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"
+
+#. (itstool) path: media
+#. This is a reference to an external file such as an image or video. When
+#. the file changes, the md5 hash will change to let you know you need to
+#. update your localized copy. The msgstr is not used at all. Set it to
+#. whatever you like once you have updated your copy of the file.
+#: tests/IT-prefixes-1.xml:7
+msgctxt "_"
+msgid "external ref='movie.avi' md5='__failed__'"
+msgstr "external ref='movie.avi' md5='__failed__'"
+
+#. (itstool) path: page/p
+#: tests/IT-prefixes-1.xml:6
+msgid "This is a test of namespace <its:span>prefixes</its:span>"
+msgstr "Ceci est un test de <its:span>préfixes</its:span> d'espace de noms."
+
+#. (itstool) path: div/p
+#: tests/IT-prefixes-1.xml:11
+msgid "Drag <tt:span>pieces</tt:span> from the right to the left."
+msgstr "Faites glisser des <tt:span>pièces</tt:span> de la gauche vers la droite."
+
+#. (itstool) path: div/p
+#: tests/IT-prefixes-1.xml:14
+msgid "Hold down <mal:key>Ctrl</mal:key>."
+msgstr "Maintenez la touche <mal:key>Ctrl</mal:key>."
+
diff --git a/tests/IT-prefixes-1.ll.xml b/tests/IT-prefixes-1.ll.xml
new file mode 100644
index 0000000..a7c0e3d
--- /dev/null
+++ b/tests/IT-prefixes-1.ll.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+<page xmlns="http://projectmallard.org/1.0/" xmlns:mal="http://projectmallard.org/1.0/" xmlns:its="http://www.w3.org/2005/11/its" xmlns:tt="http://www.w3.org/ns/ttml" xml:lang="test">
+ <p>Ceci est un test de <its:span>préfixes</its:span> d'espace de noms.</p>
+ <media type="video" src="movie.avi">
+ <tt:tt>
+ <tt:body>
+ <tt:div begin="1s" end="6s">
+ <tt:p>Faites glisser des <tt:span>pièces</tt:span> de la gauche vers la droite.</tt:p>
+ </tt:div>
+ <tt:div begin="6s" end="14s">
+ <tt:p>Maintenez la touche <mal:key>Ctrl</mal:key>.</tt:p>
+ </tt:div>
+ </tt:body>
+ </tt:tt>
+ </media>
+</page>
diff --git a/tests/IT-prefixes-1.pot b/tests/IT-prefixes-1.pot
new file mode 100644
index 0000000..a529797
--- /dev/null
+++ b/tests/IT-prefixes-1.pot
@@ -0,0 +1,36 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"POT-Creation-Date: 2012-09-20 18:22-0400\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"
+
+#. (itstool) path: media
+#. This is a reference to an external file such as an image or video. When
+#. the file changes, the md5 hash will change to let you know you need to
+#. update your localized copy. The msgstr is not used at all. Set it to
+#. whatever you like once you have updated your copy of the file.
+#: tests/IT-prefixes-1.xml:7
+msgctxt "_"
+msgid "external ref='movie.avi' md5='__failed__'"
+msgstr ""
+
+#. (itstool) path: page/p
+#: tests/IT-prefixes-1.xml:6
+msgid "This is a test of namespace <its:span>prefixes</its:span>"
+msgstr ""
+
+#. (itstool) path: div/p
+#: tests/IT-prefixes-1.xml:11
+msgid "Drag <tt:span>pieces</tt:span> from the right to the left."
+msgstr ""
+
+#. (itstool) path: div/p
+#: tests/IT-prefixes-1.xml:14
+msgid "Hold down <mal:key>Ctrl</mal:key>."
+msgstr ""
+
diff --git a/tests/IT-prefixes-1.xml b/tests/IT-prefixes-1.xml
new file mode 100644
index 0000000..c0aaf80
--- /dev/null
+++ b/tests/IT-prefixes-1.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<page xmlns="http://projectmallard.org/1.0/"
+ xmlns:mal="http://projectmallard.org/1.0/"
+ xmlns:its="http://www.w3.org/2005/11/its"
+ xmlns:tt="http://www.w3.org/ns/ttml">
+ <p>This is a test of namespace <its:span>prefixes</its:span></p>
+ <media type="video" src="movie.avi">
+ <tt:tt>
+ <tt:body>
+ <tt:div begin="1s" end="6s">
+ <tt:p>Drag <tt:span>pieces</tt:span> from the right to the left.</tt:p>
+ </tt:div>
+ <tt:div begin="6s" end="14s">
+ <tt:p>Hold down <mal:key>Ctrl</mal:key>.</tt:p>
+ </tt:div>
+ </tt:body>
+ </tt:tt>
+ </media>
+</page>
diff --git a/tests/run_tests.py b/tests/run_tests.py
index 5c108e5..5670dd3 100644
--- a/tests/run_tests.py
+++ b/tests/run_tests.py
@@ -171,6 +171,9 @@ class ItstoolTests(unittest.TestCase):
def test_IT_placeholder_1(self):
self._test_translation_process('IT-placeholder-1.xml')
+ def test_IT_prefixes_1(self):
+ self._test_translation_process('IT-prefixes-1.xml')
+
def test_IT_malformed(self):
""" Test that a malformed XML generates a proper exception """
res = self._test_pot_generation('IT-malformed.xml', expected_status=1)