Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rjollos opened this issue Feb 22, 2014 · 8 comments · Fixed by #720
Closed

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

rjollos opened this issue Feb 22, 2014 · 8 comments · Fixed by #720

Comments

@rjollos
Copy link
Contributor

rjollos commented Feb 22, 2014

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.

@sudheesh001
Copy link
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 ?

@rjollos
Copy link
Contributor Author

rjollos commented Feb 4, 2016

Both the links given hit a 404 page

Updated the links.

@akx
Copy link
Member

akx commented Feb 8, 2016

@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?

@rjollos
Copy link
Contributor Author

rjollos commented Feb 10, 2016

@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.

@jun66j5
Copy link
Contributor

jun66j5 commented Feb 10, 2016

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.
 #

@akx
Copy link
Member

akx commented Feb 12, 2016

@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? :)

@lelit
Copy link

lelit commented Feb 21, 2016

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...

@akx
Copy link
Member

akx commented Feb 21, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants