]> granicus.if.org Git - python/commitdiff
Issue #5464: Implement plural forms in msgfmt.py.
authorMartin v. Löwis <martin@v.loewis.de>
Fri, 4 Jun 2010 18:04:42 +0000 (18:04 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Fri, 4 Jun 2010 18:04:42 +0000 (18:04 +0000)
Misc/NEWS
Tools/i18n/msgfmt.py

index ca113aa8b04347ccba7c87a8c201e55e1649e249..6540d9cac7071f552ad70fb1caf2ecbae3ab4992 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -123,6 +123,12 @@ Build
 - Issues #1759169, #8864: Drop _XOPEN_SOURCE on Solaris, define it for 
   multiprocessing only.
 
+Tools/Demos
+-----------
+
+- Issue #5464: Implement plural forms in msgfmt.py.
+
+
 What's New in Python 2.7 beta 2?
 ================================
 
index 64331313cd6da95649018a8b037648650670bc81..5dd5430a5242d4341f1fde7c430982fcfbb5f237 100755 (executable)
@@ -133,16 +133,39 @@ def make(filename, outfile):
         if l[0] == '#':
             continue
         # Now we are in a msgid section, output previous section
-        if l.startswith('msgid'):
+        if l.startswith('msgid') and not l.startswith('msgid_plural'):
             if section == STR:
                 add(msgid, msgstr, fuzzy)
             section = ID
             l = l[5:]
             msgid = msgstr = ''
+            is_plural = False
+        # This is a message with plural forms
+        elif l.startswith('msgid_plural'):
+            if section != ID:
+                print >> sys.stderr, 'msgid_plural not preceeded by msgid on %s:%d' %\
+                    (infile, lno)
+                sys.exit(1)
+            l = l[12:]
+            msgid += '\0' # separator of singular and plural
+            is_plural = True
         # Now we are in a msgstr section
         elif l.startswith('msgstr'):
             section = STR
-            l = l[6:]
+            if l.startswith('msgstr['):
+                if not is_plural:
+                    print >> sys.stderr, 'plural without msgid_plural on %s:%d' %\
+                        (infile, lno)
+                    sys.exit(1)
+                l = l.split(']', 1)[1]
+                if msgstr:
+                    msgstr += '\0' # Separator of the various plural forms
+            else:
+                if is_plural:
+                    print >> sys.stderr, 'indexed msgstr required for plural on  %s:%d' %\
+                        (infile, lno)
+                    sys.exit(1)
+                l = l[6:]
         # Skip empty lines
         l = l.strip()
         if not l: