Commit graph

63 commits

Author SHA1 Message Date
Stan Ulbrych
92985e321a
gh-130195: Fix typo in warning message (#130254)
Co-authored-by: Éric <merwok@netwok.org>
2025-04-24 17:06:12 +03:00
Tomas R.
b6760b7fa5
gh-130453: pygettext: Allow specifying multiple keywords with the same function name (GH-131380) 2025-04-10 11:06:40 +00:00
Tomas R.
a693eaa710
gh-132121: Always escape non-printable characters in pygettext (GH-132122) 2025-04-06 23:15:17 +03:00
Tomas R.
87d9983994
gh-130197: pygettext: Test the --escape option (GH-131902) 2025-04-02 11:46:54 +03:00
Tomas R.
321bf59512
gh-130453: pygettext: Allow overriding default keywords when using --keyword (GH-130709) 2025-03-03 18:57:01 +02:00
Tomas R.
44213bc57c
gh-130453: pygettext: Extend support for specifying custom keywords (GH-130463) 2025-02-25 12:10:54 +02:00
Stan Ulbrych
4374e1de87
gh-130195: Remove unimplemented option from pygettext (#130196)
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
2025-02-17 19:01:36 -08:00
Tomas R.
aa845af9bb
gh-130057: Pygettext: Support translator comments (GH-130061) 2025-02-17 12:41:28 +02:00
Tomas R.
9d1e668e6f
gh-129911: pygettext: Fix the keyword entry in help output (GH-129914) 2025-02-14 11:34:09 +02:00
Tomas R.
374abded07
gh-104400: pygettext: use an AST parser instead of a tokenizer (GH-104402)
This greatly simplifies the code and fixes many corner cases.
2025-02-11 13:51:42 +02:00
Tomas R.
e41ec8e18b
gh-104400: pygettext: Prepare to replace TokenEater with a NodeVisitor (#129672)
* Update the module docstring
* Move ``key_for`` inside the class
* Move ``write_pot_file`` outside the class
2025-02-04 22:59:23 +00:00
Adam Turner
237f186da4
gh-104400: Remove `fintl.gettext` from pygettext (#129580)
The ``fintl`` module is never installed or tested, meaning that the
fallback identity function is unconditionally used for ``_()``.
This means we can simplify, converting the docstring to a real
docstring, and converting some other strings to f-strings.

We also convert the module to UTF-8, sort imports,
and remove the history comment, which was last updated in 2002.
Consult the git history for a more accurate summary of changes.
2025-02-02 14:30:34 +00:00
Tomas R.
0a1944cda8
gh-126700: pygettext: Support more gettext functions (GH-126912)
Support multi-argument gettext functions: ngettext(), pgettext(), dgettext(), etc.
2024-11-22 16:52:16 +02:00
Tomas R.
9a456383be
gh-126807: pygettext: Do not attempt to extract messages from function definitions. (GH-126808)
Fixes a bug where pygettext would attempt
to extract a message from a code like this:

def _(x): pass

This is because pygettext only looks at one
token at a time and '_(x)' looks like a
function call.

However, since 'x' is not a string literal,
it would erroneously issue a warning.
2024-11-14 22:17:42 +00:00
JosephSBoyle
b097925858
gh-102507 Remove invisible pagebreak characters (#102531)
Co-authored-by: AlexWaygood <alex.waygood@gmail.com>
2023-03-08 13:58:14 +00:00
Jakub Kuczys
120b4ab2b6
gh-95731: Fix module docstring extraction in pygettext (#95732) 2022-10-15 07:57:53 -07:00
Noah Kantrowitz
be42c06bb0
Update URLs in comments and metadata to use HTTPS (GH-27458) 2021-07-30 15:54:46 +02:00
jack1142
bfc6b63102
bpo-36310: Allow pygettext.py to detect calls to gettext in f-strings. (GH-19875)
Adds support to Tools/i18n/pygettext.py for gettext calls in f-strings. This process is done by parsing the f-strings, processing each value, and flagging the ones which contain a gettext call.

Co-authored-by: Batuhan Taskaya <batuhanosmantaskaya@gmail.com>
2020-11-10 01:50:45 +03:00
Serhiy Storchaka
172bb39452
bpo-22831: Use "with" to avoid possible fd leaks in tools (part 2). (GH-10927) 2019-03-30 08:33:02 +02:00
Serhiy Storchaka
69524821a8
bpo-33189: pygettext.py now accepts only literal strings (GH-6364)
as docstrings and translatable strings, and rejects
bytes literals and f-string expressions.
2018-04-19 09:23:03 +03:00
Serhiy Storchaka
c93938b5be
bpo-31920: Fixed handling directories as arguments in the `pygettext` script. (GH-6259)
Based on patch by Oleg Krasnikov.
2018-04-09 20:09:17 +03:00
Tobotimus
eee72d4778 bpo-32222: Fix pygettext skipping docstrings for funcs with arg typehints (GH-4745) 2018-02-27 00:48:14 +02:00
Martin Panter
02b75abf73 Merge spelling and grammar fixes from 3.5 2016-08-05 01:51:39 +00:00
Martin Panter
69332c1a64 Fix spelling and grammar in documentation and code comments 2016-08-04 13:07:31 +00:00
Victor Stinner
328cb1fed0 Update pygettext.py to get ride of imp
Issue #26639: Replace imp with importlib in Tools/i18n/pygettext.py.

Remove _get_modpkg_path(), replaced with importlib.util.find_spec().
2016-04-12 18:46:10 +02:00
R David Murray
2b78129b3a #18128: use standard +NNNN timezone format in POT-Creation-Date header.
Patch by Michael McFadden, with a few small style tweaks.
2015-04-16 12:15:09 -04:00
Benjamin Peterson
eaedaeccf2 update Barry's email (#19563) 2013-12-22 19:45:38 -06:00
Serhiy Storchaka
859cd4723f Issue #17156: pygettext.py now uses an encoding of source file and correctly
writes and escapes non-ascii characters.
2013-02-09 22:38:12 +02:00
Serhiy Storchaka
b6ed17344b Issue #17156: pygettext.py now uses an encoding of source file and correctly
writes and escapes non-ascii characters.
2013-02-09 22:37:22 +02:00
Florent Xicluna
c20740109d Some cleanup in the Tools directory. 2012-07-07 17:03:54 +02:00
Benjamin Peterson
90f5ba538b convert shebang lines: python -> python3 2010-03-11 22:53:45 +00:00
Georg Brandl
bf82e374ee More 2to3 fixes in the Tools directory. Fixes #2893. 2008-05-16 17:02:34 +00:00
Alexandre Vassalotti
4e6531e7de Removed remnants of os.path.walk(). 2008-05-09 20:00:17 +00:00
Trent Nelson
428de65ca9 - Issue #719888: Updated tokenize to use a bytes API. generate_tokens has been
renamed tokenize and now works with bytes rather than strings. A new
  detect_encoding function has been added for determining source file encoding
  according to PEP-0263. Token sequences returned by tokenize always start
  with an ENCODING token which specifies the encoding used to decode the file.
  This token is used to encode the output of untokenize back to bytes.

Credit goes to Michael "I'm-going-to-name-my-first-child-unittest" Foord from Resolver Systems for this work.
2008-03-18 22:41:35 +00:00
Guido van Rossum
f7bd964fb5 Patch #1830 by Peter Harris, fix some 2.x-isms. 2008-01-15 17:41:38 +00:00
Georg Brandl
6464d47195 In followup to #1310: Remove more exception indexing. 2007-10-22 16:16:13 +00:00
Collin Winter
6afaeb757a Convert print statements to function calls in Tools/. 2007-08-03 17:06:41 +00:00
Guido van Rossum
b940e113bf SF patch 1631942 by Collin Winter:
(a) "except E, V" -> "except E as V"
(b) V is now limited to a simple name (local variable)
(c) V is now deleted at the end of the except block
2007-01-10 16:19:56 +00:00
Guido van Rossum
89da5d7c3d Kill reduce(). A coproduction of John Reese, Jacques Frechet, and Alex M. 2006-08-22 00:21:25 +00:00
Matthias Klose
2443d4ab5d - pygettext.py: Generate POT-Creation-Date header in ISO format. 2004-08-16 12:10:12 +00:00
Barry Warsaw
e04ee70a68 Mostly reformatting, splitting long lines, whitespace normalization
etc.

Fixed one typo in the __main__ section.
2003-04-16 18:08:23 +00:00
Martin v. Löwis
0d1fdea8ef Patch #494845: Support string concatenation, detect non-string data,
add globbing support, find modules by name instead of by file.
2002-11-22 08:36:54 +00:00
Barry Warsaw
63ce5af496 Added the -X/--no-docstrings flag which takes a filename containing a
list of files to not extract docstrings from when the -D option is
given.  This isn't optimal, but I didn't want to change the semantics
of -D, and it's bad form to allow optional switch arguments.

Bumping __version__ to 1.4.

TokenEater.__init__(): Initialize __curfile to None.

__waiting(): In order to extract docstrings from the module, both the
    -D flag should be set, and the __curfile should not be named in
    the -X filename (i.e. it isn't in opts.nodocstrings).

set_filename(): Fixed a bug where once the first module docstring is
    extracted, no subsequent module docstrings will be extracted.  The
    bug was that the first extraction set __freshmodule to 0, but that
    flag was never reset back to 1.  set_filename() is always called
    when the next file is being processed, so use it to reset the
    __freshmodule flag.

main(): Add support for -X/--no-docstring.
2001-07-27 16:47:18 +00:00
Barry Warsaw
5c94ce58e7 write(): Karl Eichwalder points out that the #, flag comments should
be outputted just before the msgid lines.
2001-06-20 19:41:40 +00:00
Barry Warsaw
8c78d3a5d1 write(): It's been generally agreed on the i18n-sig that the docstring
marker should be output as a #, flag, e.g. "#, docstring".
2001-06-19 19:54:19 +00:00
Barry Warsaw
50cf706b5c write(): Aggressively sort all catalog entries, and fix the bug where
there were multiple translatable strings on a single line of source
code.
2001-05-24 23:06:13 +00:00
Barry Warsaw
128c77d03a write(): Do two levels of sorting: first sort the individual location
tuples by filename/lineno, then sort the catalog entries by their
location tuples.
2001-05-23 16:59:45 +00:00
Barry Warsaw
2b63969a5a main(): default-domain argument to getopt.getopt() was missing a = to
indicate it took an argument.  This closes SF patch #402223 by Bastian
Kleineidam.
2001-05-21 19:58:23 +00:00
Barry Warsaw
16b62c1300 __addentry(): add optional keyword arg `isdocstring' which is a flag
indicating whether the entry was extracted from a docstring or not.

write(): If any of the locations of a string appearance came from a
docstring, add a comment such as

#. docstring

before the references (after a suggestion by Martin von Loewis).
2001-05-21 19:51:26 +00:00
Barry Warsaw
6e972414be write(): A patch inspired by Tokio Kikuchi that sorts location entries
first by filename and then by line number.  Closes SF patch #425821.

Also, fixes a problem with duplicate entries.
2001-05-21 19:35:20 +00:00