Skip to content

Allow header_comment to be passed as an option to extract_message #82

Description

@rjollos

In Trac and Apache Bloodhound we utilize babel.extract_messages. For Apache Bloodhound, we'd like to be able to specify the header_comment parameter when creating the Catalog. We would like to add header_comment as an option for extract_messages.

I am planning to prepare a patch, but wanted to open the issue first in case there was any early feedback.

Activity

  1. sudheesh001 commented on Feb 4, 2016

    @sudheesh001
    Contributor

    Both the links given hit a 404 page, I understand that the changes needed are in
    class extract_messages(Command): but I already see

    ('update-header-comment', None,
             'update target header comment'),
    

    in update catalog, should this be carried over to the user_options in extract_messages ?

  2. rjollos commented on Feb 4, 2016

    @rjollos
    ContributorAuthor

    Both the links given hit a 404 page

    Updated the links.

  3. akx commented on Feb 8, 2016

    @akx
    Member

    @sudheesh001 Update is another step of the message process (it roughly goes "extract", "update", "compile").

    I think OP @rjollos would like to be able to simply set a header comment for new extractions, i.e.

    pybabel extract --header-comment=blah ...

    or the sort. Did I understand correctly?

  4. rjollos commented on Feb 10, 2016

    @rjollos
    ContributorAuthor

    @akx I may have had in mind to specify header_comment as an option in the [extract_messages] section of setup.cfg. Is that equivalent to specifying an option to pybabel extract?

    I'm not extremely familiar with the Babel code in the Trac project, but nowhere do we instantiate a Catalog object directly, so I can't see how it's possible to set header_comment.

  5. jun66j5 commented on Feb 10, 2016

    @jun66j5
    Contributor

    After the following patch, it would allow to be passed via header_comment of [extract_messages] section in setup.cfg.

    diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py
    index 9bb46bb..d6b1f53 100644
    --- a/babel/messages/frontend.py
    +++ b/babel/messages/frontend.py
    @@ -24,7 +24,7 @@ from babel import __version__ as VERSION
     from babel import Locale, localedata
     from babel._compat import StringIO, string_types
     from babel.core import UnknownLocaleError
    -from babel.messages.catalog import Catalog
    +from babel.messages.catalog import Catalog, DEFAULT_HEADER
     from babel.messages.extract import DEFAULT_KEYWORDS, DEFAULT_MAPPING, check_and_call_extract_file, extract_from_dir
     from babel.messages.mofile import write_mo
     from babel.messages.pofile import read_po, write_po
    @@ -246,6 +246,8 @@ class extract_messages(Command):
              'set project name in output'),
             ('version=', None,
              'set project version in output'),
    +        ('header-comment=', None,
    +         'set header comment for the catalog'),
             ('add-comments=', 'c',
              'place comment block with TAG (or those preceding keyword lines) in '
              'output file. Separate multiple TAGs with commas(,)'),
    @@ -283,6 +285,7 @@ class extract_messages(Command):
             self.copyright_holder = None
             self.project = None
             self.version = None
    +        self.header_comment = DEFAULT_HEADER
             self.add_comments = None
             self.strip_comments = False
    
    @@ -352,7 +355,8 @@ class extract_messages(Command):
                                   version=self.version,
                                   msgid_bugs_address=self.msgid_bugs_address,
                                   copyright_holder=self.copyright_holder,
    -                              charset=self.charset)
    +                              charset=self.charset,
    +                              header_comment=self.header_comment)
    
                 for path, (method_map, options_map) in mappings.items():
                     def callback(filename, method, options):

    Example of setup.cfg:

    [extract_messages]
    add_comments = TRANSLATOR:
    copyright_holder = ....
    msgid_bugs_address = msgid@example.com
    output_file = foobar/locale/messages.pot
    header_comment =
     # Translations template for PROJECT.
     # Copyright (C) YEAR ORGANIZATION
     # This file is distributed under the same license as the PROJECT project.
     # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
     #
    
  6. akx commented on Feb 12, 2016

    @akx
    Member

    @jun66j5 That patch looks good! (And would allow --header-comment= as a side effect.)

    Care to make a PR out of it, with a test case included? :)

  7. lelit commented on Feb 21, 2016

    @lelit

    I know it complicates the thing, but but would be nice to have a way to preserve previous bits of information. Currently the update process rewrites the whole header, in particular the last line with "FIRST AUTHOR...", effectively discarding both the original translator and the year.
    i'm going to use a brute force fix using sed and git to restore that, but it's kind of a waste...

  8. akx commented on Feb 21, 2016

    @akx
    Member

    @lelit: That sounds sensible. Care to create another issue and describe the workflow you'd like regarding all this?

  9. added a commit that references this issue on Jul 16, 2020
    45e7175
  10. added 2 commits that reference this issue on Apr 11, 2022
    7af8937
    d1d655b
  11. added a commit that references this issue on Apr 12, 2022
    61109c4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions