From b23711341c11cadd387f93c4e66f3bc692b997ca Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Sat, 23 Nov 2024 23:27:30 +0100 Subject: [PATCH 1/3] Document gettext.c2py --- Doc/library/gettext.rst | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Doc/library/gettext.rst b/Doc/library/gettext.rst index d0de83907eb297..64f9f3bdb62854 100644 --- a/Doc/library/gettext.rst +++ b/Doc/library/gettext.rst @@ -380,6 +380,25 @@ unexpected, or if other problems occur while reading the file, instantiating a .. versionadded:: 3.8 +Utility functions +^^^^^^^^^^^^^^^^^ + +.. function:: c2py(plural) + + Convert a :file:`.po` file plural rule to a Python function. + The returned function takes a single integer argument and returns the + corresponding plural index in the message catalog. See + `the GNU gettext documentation `__ + for more details about plural rules. + + Example usage:: + + >>> plural_fn = c2py('n == 1 ? 0 : 1') + >>> plural_fn(1) + 0 + >>> plural_fn(5) + 1 + Solaris message catalog support ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 76d7f57831e7363392f9adfa79f20442c7535c1a Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Thu, 28 Nov 2024 19:22:05 +0100 Subject: [PATCH 2/3] Add 'c2py' to __all__ --- Lib/gettext.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/gettext.py b/Lib/gettext.py index a0d81cf846a05c..46d06f7597bc70 100644 --- a/Lib/gettext.py +++ b/Lib/gettext.py @@ -56,8 +56,7 @@ 'bindtextdomain', 'find', 'translation', 'install', 'textdomain', 'dgettext', 'dngettext', 'gettext', 'ngettext', 'pgettext', 'dpgettext', 'npgettext', - 'dnpgettext' - ] + 'dnpgettext', 'c2py'] _default_localedir = os.path.join(sys.base_prefix, 'share', 'locale') From e0952742f97dbe382f6fd9b4ad21b17874cf65e3 Mon Sep 17 00:00:00 2001 From: Tomas Roun Date: Thu, 28 Nov 2024 19:31:19 +0100 Subject: [PATCH 3/3] Add news entry --- .../Documentation/2024-11-28-19-31-15.gh-issue-127373.tbXdH9.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Documentation/2024-11-28-19-31-15.gh-issue-127373.tbXdH9.rst diff --git a/Misc/NEWS.d/next/Documentation/2024-11-28-19-31-15.gh-issue-127373.tbXdH9.rst b/Misc/NEWS.d/next/Documentation/2024-11-28-19-31-15.gh-issue-127373.tbXdH9.rst new file mode 100644 index 00000000000000..4eebf0115a6c05 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2024-11-28-19-31-15.gh-issue-127373.tbXdH9.rst @@ -0,0 +1 @@ +Document :func:`gettext.c2py`.