Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-127373: Document gettext.c2py #127374

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Doc/library/gettext.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html>`__
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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
3 changes: 1 addition & 2 deletions Lib/gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Document :func:`gettext.c2py`.
Loading