|
1 | 1 | # Test message extraction
|
2 |
| -from gettext import gettext as _ |
| 2 | +from gettext import ( |
| 3 | + gettext, |
| 4 | + ngettext, |
| 5 | + pgettext, |
| 6 | + npgettext, |
| 7 | + dgettext, |
| 8 | + dngettext, |
| 9 | + dpgettext, |
| 10 | + dnpgettext |
| 11 | +) |
| 12 | + |
| 13 | +_ = gettext |
3 | 14 |
|
4 | 15 | # Empty string
|
5 | 16 | _("")
|
|
21 | 32 | _(None)
|
22 | 33 | _(1)
|
23 | 34 | _(False)
|
24 |
| -_(x="kwargs are not allowed") |
| 35 | +_(("invalid")) |
| 36 | +_(["invalid"]) |
| 37 | +_({"invalid"}) |
| 38 | +_("string"[3]) |
| 39 | +_("string"[:3]) |
| 40 | +_({"string": "foo"}) |
| 41 | + |
| 42 | +# pygettext does not allow keyword arguments, but both xgettext and pybabel do |
| 43 | +_(x="kwargs work!") |
| 44 | + |
| 45 | +# Unusual, but valid arguments |
25 | 46 | _("foo", "bar")
|
26 | 47 | _("something", x="something else")
|
27 | 48 |
|
28 | 49 | # .format()
|
29 | 50 | _("Hello, {}!").format("world") # valid
|
30 |
| -_("Hello, {}!".format("world")) # invalid |
| 51 | +_("Hello, {}!".format("world")) # invalid, but xgettext and pybabel extract the first string |
31 | 52 |
|
32 | 53 | # Nested structures
|
33 | 54 | _("1"), _("2")
|
@@ -62,3 +83,28 @@ def _(x):
|
62 | 83 |
|
63 | 84 | def _(x="don't extract me"):
|
64 | 85 | pass
|
| 86 | + |
| 87 | + |
| 88 | +# Other gettext functions |
| 89 | +gettext("foo") |
| 90 | +ngettext("foo", "foos", 1) |
| 91 | +pgettext("context", "foo") |
| 92 | +npgettext("context", "foo", "foos", 1) |
| 93 | +dgettext("domain", "foo") |
| 94 | +dngettext("domain", "foo", "foos", 1) |
| 95 | +dpgettext("domain", "context", "foo") |
| 96 | +dnpgettext("domain", "context", "foo", "foos", 1) |
| 97 | + |
| 98 | +# Complex arguments |
| 99 | +ngettext("foo", "foos", 42 + (10 - 20)) |
| 100 | +dgettext(["some", {"complex"}, ("argument",)], "domain foo") |
| 101 | + |
| 102 | +# Invalid calls which are not extracted |
| 103 | +gettext() |
| 104 | +ngettext('foo') |
| 105 | +pgettext('context') |
| 106 | +npgettext('context', 'foo') |
| 107 | +dgettext('domain') |
| 108 | +dngettext('domain', 'foo') |
| 109 | +dpgettext('domain', 'context') |
| 110 | +dnpgettext('domain', 'context', 'foo') |
0 commit comments