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 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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') 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`.