Rev 6359: (gz) Keep duplicates till later in the translation template generation for in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

Patch Queue Manager pqm at pqm.ubuntu.com
Mon Dec 12 13:56:18 UTC 2011


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6359 [merge]
revision-id: pqm at pqm.ubuntu.com-20111212135617-wy5lwmdr49pw9401
parent: pqm at pqm.ubuntu.com-20111212133108-m0wtlolqdsh1u9bj
parent: martin.packman at canonical.com-20111208190014-mi8jm6v7jygmhb0r
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2011-12-12 13:56:17 +0000
message:
  (gz) Keep duplicates till later in the translation template generation for
   added context (Martin Packman)
modified:
  Makefile                       Makefile-20050805140406-d96e3498bb61c5bb
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/export_pot.py           bzrgettext-20110429104643-3wjy38532whc21yj-2
  bzrlib/tests/test_export_pot.py test_export_pot.py-20110509102137-efovgz233s9uk2b2-1
=== modified file 'Makefile'
--- a/Makefile	2011-11-29 00:35:22 +0000
+++ b/Makefile	2011-12-08 19:00:14 +0000
@@ -432,7 +432,7 @@
 		)
 
 po/bzr.pot: $(PYFILES) $(DOCFILES)
-	$(PYTHON) ./bzr export-pot > po/bzr.pot
+	$(PYTHON) ./bzr export-pot --include-duplicates > po/bzr.pot
 	echo $(TRANSLATABLE_PYFILES) | xargs \
 	  xgettext --package-name "bzr" \
 	  --msgid-bugs-address "<bazaar at canonical.com>" \

=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2011-12-11 02:31:43 +0000
+++ b/bzrlib/builtins.py	2011-12-12 13:56:17 +0000
@@ -6570,11 +6570,15 @@
     takes_options = [Option('plugin', 
                             help='Export help text from named command '\
                                  '(defaults to all built in commands).',
-                            type=str)]
+                            type=str),
+                     Option('include-duplicates',
+                            help='Output multiple copies of the same msgid '
+                                 'string if it appears more than once.'),
+                            ]
 
-    def run(self, plugin=None):
+    def run(self, plugin=None, include_duplicates=False):
         from bzrlib.export_pot import export_pot
-        export_pot(self.outf, plugin)
+        export_pot(self.outf, plugin, include_duplicates)
 
 
 def _register_lazy_builtins():

=== modified file 'bzrlib/export_pot.py'
--- a/bzrlib/export_pot.py	2011-11-24 11:49:43 +0000
+++ b/bzrlib/export_pot.py	2011-12-08 18:58:27 +0000
@@ -130,15 +130,19 @@
 class _PotExporter(object):
     """Write message details to output stream in .pot file format"""
 
-    def __init__(self, outf):
+    def __init__(self, outf, include_duplicates=False):
         self.outf = outf
-        self._msgids = set()
+        if include_duplicates:
+            self._msgids = None
+        else:
+            self._msgids = set()
         self._module_contexts = {}
 
     def poentry(self, path, lineno, s, comment=None):
-        if s in self._msgids:
-            return
-        self._msgids.add(s)
+        if self._msgids is not None:
+            if s in self._msgids:
+                return
+            self._msgids.add(s)
         if comment is None:
             comment = ''
         else:
@@ -305,8 +309,8 @@
                      1, summary)
 
 
-def export_pot(outf, plugin=None):
-    exporter = _PotExporter(outf)
+def export_pot(outf, plugin=None, include_duplicates=False):
+    exporter = _PotExporter(outf, include_duplicates)
     if plugin is None:
         _standard_options(exporter)
         _command_helps(exporter)

=== modified file 'bzrlib/tests/test_export_pot.py'
--- a/bzrlib/tests/test_export_pot.py	2011-11-24 11:49:43 +0000
+++ b/bzrlib/tests/test_export_pot.py	2011-12-08 18:58:27 +0000
@@ -322,6 +322,27 @@
         self.assertNotContainsString(pot, "'protocol=old'")
 
 
+class TestPotExporter(tests.TestCase):
+    """Test for logic specific to the _PotExporter class"""
+
+    # This test duplicates test_duplicates below
+    def test_duplicates(self):
+        exporter = export_pot._PotExporter(StringIO())
+        context = export_pot._ModuleContext("mod.py", 1)
+        exporter.poentry_in_context(context, "Common line.")
+        context.lineno = 3
+        exporter.poentry_in_context(context, "Common line.")
+        self.assertEqual(1, exporter.outf.getvalue().count("Common line."))
+    
+    def test_duplicates_included(self):
+        exporter = export_pot._PotExporter(StringIO(), True)
+        context = export_pot._ModuleContext("mod.py", 1)
+        exporter.poentry_in_context(context, "Common line.")
+        context.lineno = 3
+        exporter.poentry_in_context(context, "Common line.")
+        self.assertEqual(2, exporter.outf.getvalue().count("Common line."))
+
+
 class PoEntryTestCase(tests.TestCase):
 
     def setUp(self):




More information about the bazaar-commits mailing list