summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShaun McCance <shaunm@gnome.org>2011-06-23 16:11:42 -0400
committerShaun McCance <shaunm@gnome.org>2011-06-23 16:11:42 -0400
commit4334f863ae6ab636b3e7c905e15693a188e4bee1 (patch)
tree21b6ff55aeedaafcb5a5726a03d2bc493d4f56d6
parent7ecd70b27d5cc22f8d6b35fc68aa9fe9cd3a7def (diff)
downloaditstool-4334f863ae6ab636b3e7c905e15693a188e4bee1.tar.gz
Handled translatable attributes in non-translatable elements
-rwxr-xr-xitstool.in25
-rw-r--r--tests/README4
-rw-r--r--tests/run_tests.py3
-rw-r--r--tests/x-attr1.ll.po19
-rw-r--r--tests/x-attr1.ll.xml10
-rw-r--r--tests/x-attr1.pot19
-rw-r--r--tests/x-attr1.xml10
7 files changed, 79 insertions, 11 deletions
diff --git a/itstool.in b/itstool.in
index d56a067..fcf2bf9 100755
--- a/itstool.in
+++ b/itstool.in
@@ -697,6 +697,7 @@ class Document (object):
translate = 'yes'
else:
translate = 'no'
+ withinText = False
if translate == 'no':
if msg is not None:
msg.add_placeholder(node)
@@ -707,23 +708,27 @@ class Document (object):
if is_unit:
if msg is not None:
msg.add_placeholder(node)
- # Add msg for translatable node attributes
- for attr in xml_attr_iter(node):
- if self._its_translate_nodes.get(attr, 'no') == 'yes':
- attr_msg = Message()
- attr_msg.add_source('%s:%i(%s/%s@%s)' % (
- self._doc.name, node.lineNo(), node.parent.name, node.name, attr.name))
- attr_msg.add_text(attr.content)
- if comments:
- attr_msg.add_comment(self.get_its_loc_note(attr))
- self._msgs.add_message(attr_msg, attr)
msg = Message()
if self.get_preserve_space(node):
msg.set_preserve_space()
msg.add_source('%s:%i(%s/%s)' % (self._doc.name, node.lineNo(), node.parent.name, node.name))
else:
+ withinText = True
msg.add_start_tag(node)
+ if not withinText:
+ # Add msg for translatable node attributes
+ for attr in xml_attr_iter(node):
+ if self._its_translate_nodes.get(attr, 'no') == 'yes':
+ attr_msg = Message()
+ attr_msg.add_source('%s:%i(%s/%s@%s)' % (
+ self._doc.name, node.lineNo(), node.parent.name, node.name, attr.name))
+ attr_msg.add_text(attr.content)
+ if comments:
+ attr_msg.add_comment(self.get_its_loc_note(attr))
+ self._msgs.add_message(attr_msg, attr)
+
+
if comments and msg is not None:
msg.add_comment(self.get_its_loc_note(node))
diff --git a/tests/README b/tests/README
index 0556dfe..1d3d74a 100644
--- a/tests/README
+++ b/tests/README
@@ -1,5 +1,7 @@
To run the test suite, place yourself in the itstool root directory and run:
$ python tests/run_tests.py
-Test files are coming from:
+Some test files are taken from the W3C:
http://www.w3.org/International/its/tests/
+
+Tests starting with x- are written specifically for itstool.
diff --git a/tests/run_tests.py b/tests/run_tests.py
index fe8727c..38bf025 100644
--- a/tests/run_tests.py
+++ b/tests/run_tests.py
@@ -110,6 +110,9 @@ class ItstoolTests(unittest.TestCase):
def test_withintext_linkedrules(self):
self._test_translation_process('WithinText2.xml')
+ def test_attr1(self):
+ self._test_translation_process('x-attr1.xml')
+
class ITSTestRunner(unittest.TextTestRunner):
def run(self, test):
diff --git a/tests/x-attr1.ll.po b/tests/x-attr1.ll.po
new file mode 100644
index 0000000..e7487b8
--- /dev/null
+++ b/tests/x-attr1.ll.po
@@ -0,0 +1,19 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"POT-Creation-Date: 2011-06-23 16:08-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"
+
+#: tests/x-attr1.xml:9(page/code@title)
+msgid "one"
+msgstr "eins"
+
+#: tests/x-attr1.xml:9(code/span@title)
+msgid "two"
+msgstr "zwei"
+
diff --git a/tests/x-attr1.ll.xml b/tests/x-attr1.ll.xml
new file mode 100644
index 0000000..e256afc
--- /dev/null
+++ b/tests/x-attr1.ll.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<page>
+ <info>
+ <its:rules xmlns:its="http://www.w3.org/2005/11/its" version="1.0">
+ <its:translateRule selector="//code" translate="no"/>
+ <its:translateRule selector="//@title" translate="yes"/>
+ </its:rules>
+ </info>
+ <code title="eins">Not translated <span title="zwei"/></code>
+</page>
diff --git a/tests/x-attr1.pot b/tests/x-attr1.pot
new file mode 100644
index 0000000..f2eb0df
--- /dev/null
+++ b/tests/x-attr1.pot
@@ -0,0 +1,19 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"POT-Creation-Date: 2011-06-23 16:08-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"
+
+#: tests/x-attr1.xml:9(page/code@title)
+msgid "one"
+msgstr ""
+
+#: tests/x-attr1.xml:9(code/span@title)
+msgid "two"
+msgstr ""
+
diff --git a/tests/x-attr1.xml b/tests/x-attr1.xml
new file mode 100644
index 0000000..3233132
--- /dev/null
+++ b/tests/x-attr1.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<page>
+ <info>
+ <its:rules xmlns:its="http://www.w3.org/2005/11/its" version="1.0">
+ <its:translateRule selector="//code" translate="no"/>
+ <its:translateRule selector="//@title" translate="yes"/>
+ </its:rules>
+ </info>
+ <code title="one">Not translated <span title="two"/></code>
+</page>