# HG changeset patch # User palgarvio # Date 1181464941 0 # Node ID d0d8d6cd8601d05b0fc7b514cf33c8222dd1d941 # Parent c75fa55a65b93ef08b815beb42044d227f5c6a7e Fixed the plurals header on `Catalog` which should only be written if it's not a catalog template. Added support to the frontends for `--msgid-bugs-address` that set's the `Report-Msgid-Bugs-To` header, which was also a missing header on `Catalog`, so, a bug found by chance :) (See #12, item 6) diff --git a/babel/messages/catalog.py b/babel/messages/catalog.py --- a/babel/messages/catalog.py +++ b/babel/messages/catalog.py @@ -103,17 +103,23 @@ class Catalog(object): - """Representation a message catalog.""" + """Representation of a message catalog.""" def __init__(self, locale=None, domain=None, project=None, version=None, - creation_date=None, revision_date=None, last_translator=None, - charset='utf-8'): + msgid_bugs_address=None, creation_date=None, + revision_date=None, last_translator=None, charset='utf-8'): """Initialize the catalog object. - :param domain: the message domain :param locale: the locale identifier or `Locale` object, or `None` if the catalog is not bound to a locale (which basically means it's a template) + :param domain: the message domain + :param project: the project's name + :param version: the project's version + :param msgid_bugs_address: the address to report bugs about the catalog + :param creation_date: the date the catalog was created + :param revision_date: the date the catalog was revised + :param last_translator: the name and email of the last translator """ self.domain = domain #: the message domain if locale: @@ -122,8 +128,9 @@ self._messages = odict() self.project = project or 'PROJECT' #: the project name - self.version = version or 'VERSION' #: the project version - + self.version = version or 'VERSION' #: the project version + self.msgid_bugs_address = msgid_bugs_address or 'EMAIL@ADDRESS' + if creation_date is None: creation_date = time.localtime() elif isinstance(creation_date, datetime): @@ -145,6 +152,7 @@ headers = [] headers.append(('Project-Id-Version', '%s %s' % (self.project, self.version))) + headers.append(('Report-Msgid-Bugs-To', self.msgid_bugs_address)) headers.append(('POT-Creation-Date', time.strftime('%Y-%m-%d %H:%M%z', self.creation_date))) if self.locale is None: @@ -156,11 +164,12 @@ time.strftime('%Y-%m-%d %H:%M%z', self.revision_date))) headers.append(('Last-Translator', self.last_translator)) headers.append(('Language-Team', '%s ' % self.locale)) - headers.append(('Plural-Forms', self.plural_forms)) headers.append(('MIME-Version', '1.0')) headers.append(('Content-Type', 'text/plain; charset=%s' % self.charset)) headers.append(('Content-Transfer-Encoding', '8bit')) + if self.locale is not None: + headers.append(('Plural-Forms', self.plural_forms)) headers.append(('Generated-By', 'Babel %s' % VERSION)) return headers headers = property(headers, doc="""\ @@ -177,11 +186,11 @@ >>> for name, value in catalog.headers: ... print '%s: %s' % (name, value) Project-Id-Version: Foobar 1.0 + Report-Msgid-Bugs-To: EMAIL@ADDRESS POT-Creation-Date: 1990-04-01 15:30+0000 PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE Last-Translator: FULL NAME Language-Team: LANGUAGE - Plural-Forms: nplurals=INTEGER; plural=EXPRESSION MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit @@ -196,14 +205,15 @@ >>> for name, value in catalog.headers: ... print '%s: %s' % (name, value) Project-Id-Version: Foobar 1.0 + Report-Msgid-Bugs-To: EMAIL@ADDRESS POT-Creation-Date: 1990-04-01 15:30+0000 PO-Revision-Date: 1990-08-03 12:00+0000 Last-Translator: John Doe Language-Team: de_DE - Plural-Forms: nplurals=2; plural=(n != 1) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit + Plural-Forms: nplurals=2; plural=(n != 1) Generated-By: Babel ... :type: `list` diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py --- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -83,6 +83,8 @@ 'generate sorted output (default False)'), ('sort-by-file', None, 'sort output by file location (default False)'), + ('msgid-bugs-address=', None, + 'set report address for msgid'), ('input-dirs=', None, 'directories that should be scanned for messages'), ] @@ -104,6 +106,7 @@ self.no_wrap = False self.sort_output = False self.sort_by_file = False + self.msgid_bugs_address = None def finalize_options(self): if self.no_default_keywords and not self.keywords: @@ -136,7 +139,7 @@ mappings = self._get_mappings() outfile = open(self.output_file, 'w') try: - catalog = Catalog() + catalog = Catalog(msgid_bugs_address=self.msgid_bugs_address) for dirname, (method_map, options_map) in mappings.items(): def callback(filename, method, options): if method == 'ignore': @@ -402,6 +405,9 @@ parser.add_option('--sort-by-file', dest='sort_by_file', action='store_true', help='sort output by file location (default False)') + parser.add_option('--msgid-bugs-address', dest='msgid_bugs_address', + metavar='EMAIL@ADDRESS', + help='set report address for msgid') parser.set_defaults(charset='utf-8', keywords=[], no_default_keywords=False, no_location=False, @@ -447,7 +453,7 @@ "exclusive") try: - catalog = Catalog() + catalog = Catalog(msgid_bugs_address=options.msgid_bugs_address) for dirname in args: if not os.path.isdir(dirname): parser.error('%r is not a directory' % dirname) diff --git a/babel/messages/pofile.py b/babel/messages/pofile.py --- a/babel/messages/pofile.py +++ b/babel/messages/pofile.py @@ -222,8 +222,8 @@ return u'""\n' + u'\n'.join([escape(l) for l in lines]) def write_pot(fileobj, catalog, project='PROJECT', version='VERSION', width=76, - charset='utf-8', no_location=False, omit_header=False, - sort_output=False, sort_by_file=False): + charset='utf-8', no_location=False, omit_header=False, + sort_output=False, sort_by_file=False): r"""Write a ``gettext`` PO (portable object) template file for a given message catalog to the provided file-like object. diff --git a/doc/cmdline.txt b/doc/cmdline.txt --- a/doc/cmdline.txt +++ b/doc/cmdline.txt @@ -63,6 +63,8 @@ output line width, into several lines --sort-output generate sorted output (default False) --sort-by-file sort output by file location (default False) + --msgid-bugs-address=EMAIL@ADDRESS + set report address for msgid init diff --git a/doc/setup.txt b/doc/setup.txt --- a/doc/setup.txt +++ b/doc/setup.txt @@ -60,6 +60,7 @@ output line width, into several lines --sort-output generate sorted output (default False) --sort-by-file sort output by file location (default False) + --msgid-bugs-address set report address for msgid --input-dirs directories that should be scanned for messages usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]