Mailing List Archive

[pygettext] --package-name and --package-version unknown
Hello,

am I right to assume that "pygettext" is part of the official Python3
"package"? So it is OK to aks here?

I do use pygettext to handle po and pot files. In the manpage I'm not
able to find help about this.
I would like to modify the header that pygettext does create in each
po-file.

How can I set the "Project-Id-Version"? With "xgettext" I would use the
arguments "--package-name" and "--package-version" for this but they are
unknown for "pygettext".

Kind
Christian
--
https://mail.python.org/mailman/listinfo/python-list
Re: [pygettext] --package-name and --package-version unknown [ In reply to ]
On 04/05/2023 22:38, c.buhtz@posteo.jp wrote:
> Hello,
>
> am I right to assume that "pygettext" is part of the official Python3
> "package"? So it is OK to aks here?
>

No it doesn't appear to be. It is not listed in the standard library.
It is mentioned in the documentation for gettext which is part of the
standard library.

It does seem to be part of the Python i18n toolkit however.
There are extensive comments in the .py file.

https://github.com/python/cpython/tree/main/Tools/i18n/pygettext.py

> I would like to modify the header that pygettext does create in each
> po-file.

Sorry, I've never used pygettext so can't help there.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


--
https://mail.python.org/mailman/listinfo/python-list
Re: [pygettext] --package-name and --package-version unknown [ In reply to ]
On 5/4/23 17:38, c.buhtz@posteo.jp wrote:
> am I right to assume that "pygettext" is part of the official Python3
> "package"? So it is OK to aks here?
>
> How can I set the "Project-Id-Version"? With "xgettext" I would use the
> arguments "--package-name" and "--package-version" for this but they are
> unknown for "pygettext".

pygettext is deprecated since xgettext supports python now, so using
xgettext is recommended.

That being said, pygettext does not support the options, but it could be
modified pretty easily.
Untested but if you wanted to add that functionality in just create a
modified pygettext.py with something like:


link PACKAGE and VERSION to variables:

pot_header = _('''\
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: %(packagename)s %(packageversion)s\\n"
"POT-Creation-Date: %(time)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: %(encoding)s\\n"
"Generated-By: pygettext.py %(version)s\\n"
''')

add attributes to Options class:

class Options:
# constants
GNU = 1
SOLARIS = 2
# defaults
extractall = 0 # FIXME: currently this option has no effect at all.
escape = 0
keywords = []
outpath = ''
outfile = 'messages.pot'
writelocations = 1
locationstyle = GNU
verbose = 0
width = 78
excludefilename = ''
docstrings = 0
nodocstrings = {}
packagename = "PACKAGE"
packageversion = "VERSION"

modify option parsing for loop to look for new options:
for opt, arg in opts:

elif opt in ('--package-name',):
options.packagename = arg
elif opt in ('--package-version',):
options.packageversion = arg

grab those options when generating file output:

def write(self, fp):
options = self.__options
packagename = options.packagename
packageversion = options.packageversion
timestamp = time.strftime('%Y-%m-%d %H:%M%z')
encoding = fp.encoding if fp.encoding else 'UTF-8'
print(pot_header % {'packagename': packagename,
'packageversion': packageversion,
'time': timestamp, 'version': __version__,
'charset': encoding,
'encoding': '8bit'}, file=fp)

(did not test, so might be a bug or two)

--
https://mail.python.org/mailman/listinfo/python-list
Re: [pygettext] --package-name and --package-version unknown [ In reply to ]
Thanks for the answer.

Am 05.05.2023 03:24 schrieb aapost:
> pygettext is deprecated since xgettext supports python now, so using
> xgettext is recommended.

If this is the official case then it should be mentioned in the python
docs. The 3.11 docs still tell about pygettext and xgettext and don't
recommend one of it.
--
https://mail.python.org/mailman/listinfo/python-list
Re: [pygettext] --package-name and --package-version unknown [ In reply to ]
On 5/5/23 04:39, c.buhtz@posteo.jp wrote:
> Thanks for the answer.
>
> Am 05.05.2023 03:24 schrieb aapost:
>> pygettext is deprecated since xgettext supports python now, so using
>> xgettext is recommended.
>
> If this is the official case then it should be mentioned in the python
> docs. The 3.11 docs still tell about pygettext and xgettext and don't
> recommend one of it.

Yep, no disagreement. A lot of things 'should' be though, and
technically it is (which docs being the key, lol):

$man pygettext

PYGETTEXT(1) General Commands
Manual PYGETTEXT(1)

NAME
pygettext - Python equivalent of xgettext(1)

SYNOPSIS
pygettext [OPTIONS] INPUTFILE ...

DESCRIPTION
pygettext is deprecated. The current version of xgettext
supports many languages, including Python.

pygettext uses Python's standard tokenize module to scan Python
source code, generating .pot files identical to what
GNU xgettext generates for C and C++ code. From there, the
standard GNU tools can be used.

pygettext searches only for _() by default, even though GNU
xgettext recognizes the following keywords: gettext,
dgettext, dcgettext, and gettext_noop. See the -k/--keyword flag
below for how to augment this.


(I have never used either, I just spent a few minutes trying to be
helpful =P)
--
https://mail.python.org/mailman/listinfo/python-list
Re: [pygettext] --package-name and --package-version unknown [ In reply to ]
On 5/5/23 04:39, c.buhtz@posteo.jp wrote:
>
That being said, the git repo linked earlier has accepted commits to
that file earlier this year. So read in to that what you will *shrugs*
--
https://mail.python.org/mailman/listinfo/python-list