changeset 70:620fdd25657a

Add back POT header broken in previous check-in.
author cmlenz
date Fri, 08 Jun 2007 15:47:00 +0000
parents 1d8e81bfedf9
children b260ffa01a2d
files babel/messages/catalog.py babel/messages/pofile.py
diffstat 2 files changed, 32 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/babel/messages/catalog.py
+++ b/babel/messages/catalog.py
@@ -35,7 +35,7 @@
 class Message(object):
     """Representation of a single message in a catalog."""
 
-    def __init__(self, id, string=None, locations=(), flags=()):
+    def __init__(self, id, string='', locations=(), flags=()):
         """Create the message object.
         
         :param id: the message ID, or a ``(singular, plural)`` tuple for
@@ -46,6 +46,8 @@
         :param flags: a set or sequence of flags
         """
         self.id = id
+        if not string and self.pluralizable:
+            string = (u'', u'')
         self.string = string
         self.locations = locations
         self.flags = set(flags)
@@ -104,7 +106,8 @@
     """Representation a message catalog."""
 
     def __init__(self, locale=None, domain=None, project=None, version=None,
-                 creation_date=None, revision_date=None, last_translator=None):
+                 creation_date=None, revision_date=None, last_translator=None,
+                 charset='utf-8'):
         """Initialize the catalog object.
         
         :param domain: the message domain
@@ -136,6 +139,7 @@
             revision_date = revision_date.timetuple()
         self.revision_date = revision_date #: last revision date of the catalog
         self.last_translator = last_translator #: last translator name + email
+        self.charset = charset or 'utf-8'
 
     def headers(self):
         headers = []
@@ -154,7 +158,8 @@
             headers.append(('Language-Team', '%s <LL@li.org>' % self.locale))
         headers.append(('Plural-Forms', self.plural_forms))
         headers.append(('MIME-Version', '1.0'))
-        headers.append(('Content-Type', 'text/plain; charset=utf-8'))
+        headers.append(('Content-Type',
+                        'text/plain; charset=%s' % self.charset))
         headers.append(('Content-Transfer-Encoding', '8bit'))
         headers.append(('Generated-By', 'Babel %s' % VERSION))
         return headers
@@ -204,6 +209,16 @@
     :type: `list`
     """)
 
+    def num_plurals(self):
+        num = 2
+        if self.locale:
+            if str(self.locale) in PLURALS:
+                num = PLURALS[str(self.locale)][0]
+            elif self.locale.language in PLURALS:
+                num = PLURALS[self.locale.language][0]
+        return num
+    num_plurals = property(num_plurals)
+
     def plural_forms(self):
         num, expr = ('INTEGER', 'EXPRESSION')
         if self.locale:
@@ -294,6 +309,7 @@
             if isinstance(id, (list, tuple)):
                 singular, plural = id
                 id = singular
+                assert isinstance(message.string, (list, tuple))
             self._messages[id] = message
 
     def add(self, id, string=None, locations=(), flags=()):
--- a/babel/messages/pofile.py
+++ b/babel/messages/pofile.py
@@ -128,27 +128,13 @@
     return catalog
 
 POT_HEADER = """\
-# Translations template for %%(project)s.
-# Copyright (C) %%(year)s ORGANIZATION
+# Translations template for %(project)s.
+# Copyright (C) %(year)s ORGANIZATION
 # This file is distributed under the same license as the
-# %%(project)s project.
+# %(project)s project.
 # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
 #
-#, fuzzy""" 
-
-# msgid ""
-# msgstr ""
-# "Project-Id-Version: %%(project)s %%(version)s\\n"
-# "POT-Creation-Date: %%(creation_date)s\\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=%%(charset)s\\n"
-# "Content-Transfer-Encoding: 8bit\\n"
-# "Generated-By: Babel %s\\n"
-# 
-# """ % VERSION
+""" 
 
 WORD_SEP = re.compile('('
     r'\s+|'                                 # any whitespace
@@ -281,6 +267,10 @@
             text = text.encode(charset)
         fileobj.write(text)
 
+    catalog.project = project
+    catalog.version = version
+    catalog.charset = charset
+
     for message in catalog:
         if not message.id: # This is the header "message"
             if omit_header:
@@ -288,9 +278,6 @@
             _write(POT_HEADER % {
                 'year': time.strftime('%Y'),
                 'project': project,
-                'version': version,
-                'creation_date': time.strftime('%Y-%m-%d %H:%M%z'),
-                'charset': charset,
             })
 
         if not no_location:
@@ -305,11 +292,11 @@
         if isinstance(message.id, (list, tuple)):
             _write('msgid %s\n' % _normalize(message.id[0]))
             _write('msgid_plural %s\n' % _normalize(message.id[1]))
-            _write('msgstr[0] ""\n')
-            _write('msgstr[1] ""\n')
+            for i, string in enumerate(message.string):
+                _write('msgstr[%d] %s\n' % (i, _normalize(message.string[i])))
         else:
             _write('msgid %s\n' % _normalize(message.id))
-            _write('msgstr ""\n')
+            _write('msgstr %s\n' % _normalize(message.string or ''))
         _write('\n')
 
 def write_po(fileobj, input_fileobj, locale_obj, project='PROJECT',
@@ -321,7 +308,7 @@
     >>> from StringIO import StringIO
     >>> from babel import Locale
     >>> locale_obj = Locale.parse('pt_PT')
-    >>> inbuf = StringIO(r'''# Translations Template for FooBar.
+    >>> inbuf = StringIO(r'''# Translations template for FooBar.
     ... # Copyright (C) 2007 ORGANIZATION
     ... # This file is distributed under the same license as the
     ... # FooBar project.
@@ -398,7 +385,7 @@
     in_header = True
     for index in range(len(inlines)):
         if in_header:
-            if '# Translations Template' in inlines[index]:                
+            if '# Translations template' in inlines[index]:                
                 outlines.append('# %s Translations for %s\n' % \
                                 (locale_obj.english_name, project))                
             elif '# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.' in inlines[index]:
Copyright (C) 2012-2017 Edgewall Software