Patchwork [2,of,9] i18n: posplit writes a warning for translators before rst directives

login
register
mail settings
Submitter Simon Heimberg
Date Feb. 3, 2014, 9 p.m.
Message ID <872652ec1f198881ef9e.1391461222@lapsi.heimberg.home>
Download mbox | patch
Permalink /patch/3442/
State Accepted
Commit ff6ab0b2ebf7c689d4bd307f62984dad682e364d
Headers show

Comments

Simon Heimberg - Feb. 3, 2014, 9 p.m.
# HG changeset patch
# User Simon Heimberg <simohe@besonet.ch>
# Date 1391459495 -3600
#      Mon Feb 03 21:31:35 2014 +0100
# Branch stable
# Node ID 872652ec1f198881ef9e0254987654f5746ca143
# Parent  06767c63f5065b4c4e990b8395e78a7baab277fe
i18n: posplit writes a warning for translators before rst directives

rst directives like this one have been translated:
.. note::

To help the translator include a comment before such messages.

An entry containing a rst directive now looks like this:

#. do not translate: .. note::
#: path/to/file:75
msgid = ".. note:: to think about"
msgstr = ...

Patch

diff -r 06767c63f506 -r 872652ec1f19 i18n/posplit
--- a/i18n/posplit	Sun Nov 17 20:16:14 2013 +0100
+++ b/i18n/posplit	Mon Feb 03 21:31:35 2014 +0100
@@ -5,6 +5,7 @@ 
 # license: MIT/X11/Expat
 #
 
+import re
 import sys
 import polib
 
@@ -30,6 +31,7 @@ 
     cache = {}
     entries = po[:]
     po[:] = []
+    findd = re.compile(r' *\.\. (\w+)::') # for finding directives
     for entry in entries:
         msgids = entry.msgid.split(u'\n\n')
         if entry.msgstr:
@@ -51,6 +53,14 @@ 
         for msgid, msgstr in zip(msgids, msgstrs):
             if msgid:
                 newentry = mkentry(entry, delta, msgid, msgstr)
+                mdirective = findd.match(msgid)
+                if mdirective:
+                    directive = mdirective.group(1)
+                    comment = 'do not translate: .. %s::' % directive
+                    if not newentry.comment:
+                        newentry.comment = comment
+                    elif comment not in newentry.comment:
+                        newentry.comment += '\n' + comment
                 addentry(po, newentry, cache)
             delta += 2 + msgid.count('\n')
     po.save()