Skip to content

Commit 0425936

Browse files
committed
Align --exclude-file behaviour with xgettext
Allows passing a regular PO file as an exclude file. All msgids in this file will be excluded when extracting. This adds PO parsing capability to pygettext.
1 parent 6969bc3 commit 0425936

File tree

8 files changed

+761
-29
lines changed

8 files changed

+761
-29
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# SOME DESCRIPTIVE TITLE.
2+
# Copyright (C) YEAR ORGANIZATION
3+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: PACKAGE VERSION\n"
8+
"POT-Creation-Date: 2000-01-01 00:00+0000\n"
9+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
10+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
11+
"Language-Team: LANGUAGE <[email protected]>\n"
12+
"MIME-Version: 1.0\n"
13+
"Content-Type: text/plain; charset=UTF-8\n"
14+
"Content-Transfer-Encoding: 8bit\n"
15+
"Generated-By: pygettext.py 1.5\n"
16+
17+
18+
msgid "excluded"
19+
msgstr ""
20+
21+
msgid "multiline\nexcluded"
22+
msgstr ""
23+
24+
msgid "singular excluded"
25+
msgid_plural "plural excluded"
26+
msgstr[0] ""
27+
msgstr[1] ""
28+
29+
msgctxt "context"
30+
msgid "context excluded"
31+
msgstr ""
32+
33+
msgctxt "context"
34+
msgid "context singular excluded"
35+
msgid_plural "context plural excluded"
36+
msgstr[0] ""
37+
msgstr[1] ""
38+

Lib/test/test_tools/i18n_data/excluded.pot

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,3 @@ msgstr ""
1919
msgid "foo"
2020
msgstr ""
2121

22-
#: excluded.py:12
23-
msgid ""
24-
"msgids containing newlines \n"
25-
"cannot be currently excluded"
26-
msgstr ""
27-
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import gettext as _
1+
from gettext import gettext as _, ngettext, npgettext, pgettext
22

33

44
_('foo')
55

66
_('excluded')
77

8-
_('also excluded')
8+
_('multiline\nexcluded')
99

10-
_('excluded with trailing whitespace ')
10+
ngettext('singular excluded', 'plural excluded', 2)
1111

12-
_('msgids containing newlines \n'
13-
'cannot be currently excluded')
12+
pgettext('context', 'context excluded')
13+
14+
npgettext('context', 'context singular excluded', 'context plural excluded', 2)

Lib/test/test_tools/i18n_data/excluded.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
[
2+
{
3+
"msgctxt": null,
4+
"msgid": "",
5+
"msgid_plural": null,
6+
"msgstr": "Project-Id-Version: PACKAGE VERSION\nPOT-Creation-Date: 2024-10-26 18:06+0200\nPO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\nLast-Translator: FULL NAME <EMAIL@ADDRESS>\nLanguage-Team: LANGUAGE <[email protected]>\nMIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n"
7+
},
8+
{
9+
"msgctxt": null,
10+
"msgid": "foo",
11+
"msgid_plural": null,
12+
"msgstr": "bar"
13+
},
14+
{
15+
"msgctxt": null,
16+
"msgid": "Escape sequences \" \n \t",
17+
"msgid_plural": null,
18+
"msgstr": ""
19+
},
20+
{
21+
"msgctxt": null,
22+
"msgid": "Python",
23+
"msgid_plural": null,
24+
"msgstr": "Python"
25+
},
26+
{
27+
"msgctxt": null,
28+
"msgid": "Python (2)",
29+
"msgid_plural": null,
30+
"msgstr": "Python (2)"
31+
},
32+
{
33+
"msgctxt": null,
34+
"msgid": "αβ",
35+
"msgid_plural": null,
36+
"msgstr": "αβ"
37+
},
38+
{
39+
"msgctxt": null,
40+
"msgid": "barbaz",
41+
"msgid_plural": null,
42+
"msgstr": "quxxyz"
43+
},
44+
{
45+
"msgctxt": null,
46+
"msgid": "xyz",
47+
"msgid_plural": null,
48+
"msgstr": ""
49+
},
50+
{
51+
"msgctxt": "context",
52+
"msgid": "foo",
53+
"msgid_plural": null,
54+
"msgstr": "bar"
55+
},
56+
{
57+
"msgctxt": "xyz",
58+
"msgid": "foo",
59+
"msgid_plural": null,
60+
"msgstr": "bar"
61+
},
62+
{
63+
"msgctxt": null,
64+
"msgid": "One email sent.",
65+
"msgid_plural": "%d emails sent.",
66+
"msgstr": [
67+
"One email sent.",
68+
"%d emails sent."
69+
]
70+
},
71+
{
72+
"msgctxt": null,
73+
"msgid": "One message sent.",
74+
"msgid_plural": "%d messages sent.",
75+
"msgstr": [
76+
"%d message sent."
77+
]
78+
},
79+
{
80+
"msgctxt": "abc",
81+
"msgid": "One email sent.",
82+
"msgid_plural": "%d emails sent.",
83+
"msgstr": [
84+
"One email sent.",
85+
"%d emails sent."
86+
]
87+
},
88+
{
89+
"msgctxt": null,
90+
"msgid": "qux",
91+
"msgid_plural": "quxs",
92+
"msgstr": [
93+
"abc",
94+
"xyz"
95+
]
96+
},
97+
{
98+
"msgctxt": null,
99+
"msgid": "baz",
100+
"msgid_plural": null,
101+
"msgstr": ""
102+
}
103+
]
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
msgid ""
2+
msgstr ""
3+
"Project-Id-Version: PACKAGE VERSION\n"
4+
"POT-Creation-Date: 2024-10-26 18:06+0200\n"
5+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
6+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
7+
"Language-Team: LANGUAGE <[email protected]>\n"
8+
"MIME-Version: 1.0\n"
9+
"Content-Type: text/plain; charset=UTF-8\n"
10+
"Content-Transfer-Encoding: 8bit\n"
11+
12+
msgid "foo"
13+
msgstr "bar"
14+
15+
# Selected escape sequences are allowed
16+
msgid "Escape sequences \" \n \t"
17+
msgstr ""
18+
19+
# Octal escape sequences are allowed
20+
msgid "\120\171\164\150\157\156"
21+
msgstr "Python"
22+
23+
# Hex escape sequences are allowed
24+
msgid "\x50\x79\x74\x68\x6f\x6e (2)"
25+
msgstr "Python (2)"
26+
27+
# non-ascii
28+
msgid "αβ"
29+
msgstr "αβ"
30+
31+
# Empty lines are ignored
32+
msgid ""
33+
"bar"
34+
35+
"baz"
36+
msgstr ""
37+
"qux"
38+
39+
"xyz"
40+
41+
# Keyword line does not need to contain a string
42+
msgid
43+
"xyz"
44+
msgstr ""
45+
46+
# comment
47+
# comment
48+
49+
msgctxt "context"
50+
msgid "foo"
51+
msgstr "bar"
52+
53+
msgctxt "xyz"
54+
msgid "foo"
55+
msgstr "bar"
56+
57+
msgid "One email sent."
58+
msgid_plural "%d emails sent."
59+
msgstr[0] "One email sent."
60+
msgstr[1] "%d emails sent."
61+
62+
# Each message can have a different number of msgstr[N]
63+
msgid "One message sent."
64+
msgid_plural "%d messages sent."
65+
msgstr[0] "%d message sent."
66+
67+
msgctxt "abc"
68+
msgid "One email sent."
69+
msgid_plural "%d emails sent."
70+
msgstr[0] "One email sent."
71+
msgstr[1] "%d emails sent."
72+
73+
msgid "qux"
74+
msgid_plural "quxs"
75+
msgstr[0] "a"
76+
"b"
77+
"c"
78+
msgstr[1] "x"
79+
"y"
80+
"z"
81+
82+
msgid "baz"
83+
msgstr ""
84+
85+
# trailing comments are allowed

0 commit comments

Comments
 (0)