diff babel/messages/pofile.py @ 335:4db404d0c19b trunk

More preparation for msgctxt support (#54).
author cmlenz
date Wed, 11 Jun 2008 18:56:27 +0000
parents 1786dce4b1b0
children 2ee7dc04836c
line wrap: on
line diff
--- a/babel/messages/pofile.py
+++ b/babel/messages/pofile.py
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2007 Edgewall Software
+# Copyright (C) 2007-2008 Edgewall Software
 # All rights reserved.
 #
 # This software is licensed as described in the file COPYING, which
@@ -136,6 +136,7 @@
     user_comments = []
     auto_comments = []
     obsolete = [False]
+    context = []
     in_msgid = [False]
     in_msgstr = [False]
 
@@ -149,15 +150,20 @@
             string = tuple([denormalize(t[1]) for t in translations])
         else:
             string = denormalize(translations[0][1])
+        if context:
+            msgctxt = denormalize('\n'.join(context))
+        else:
+            msgctxt = None
         message = Message(msgid, string, list(locations), set(flags),
-                          auto_comments, user_comments, lineno=offset[0] + 1)
+                          auto_comments, user_comments, lineno=offset[0] + 1,
+                          context=msgctxt)
         if obsolete[0]:
             if not ignore_obsolete:
                 catalog.obsolete[msgid] = message
         else:
             catalog[msgid] = message
-        del messages[:]; del translations[:]; del locations[:];
-        del flags[:]; del auto_comments[:]; del user_comments[:]
+        del messages[:]; del translations[:]; del context[:]; del locations[:];
+        del flags[:]; del auto_comments[:]; del user_comments[:];
         obsolete[0] = False
         counter[0] += 1
 
@@ -182,11 +188,16 @@
                 translations.append([int(idx), msg.lstrip()])
             else:
                 translations.append([0, msg])
+        elif line.startswith('msgctxt'):
+            in_msgid[0] = in_msgstr[0] = False
+            context.append(line[7:].lstrip())
         elif line.startswith('"'):
             if in_msgid[0]:
                 messages[-1] += u'\n' + line.rstrip()
             elif in_msgstr[0]:
                 translations[-1][1] += u'\n' + line.rstrip()
+            elif in_msgctxt[0]:
+                context.append(line.rstrip())
 
     for lineno, line in enumerate(fileobj.readlines()):
         line = line.strip().decode(catalog.charset)
Copyright (C) 2012-2017 Edgewall Software