mirror of
https://github.com/facebook/sapling.git
synced 2024-10-16 11:52:02 +03:00
6f7fabcecf
Summary: Support pluralized translation strings using ngettext. This allows strings that are appropriately pluralized based on the count of the item. To use import `_n` from the `i18n` module and provide it with singular and plural messages, along with the count of the item that should be pluralized: ``` from mercurial.i18n import _n ui.write(_n("%d item processed", "%d items processed", count) % count) ``` When using `%`-based string formatting in Python, both variants of the format string must have the same number of subsitutions: it's not possible to leave out the `%d` in the singular case. Reviewed By: quark-zju Differential Revision: D12921684 fbshipit-source-id: 756d1350a827d0451a07279f6884ee57dba6ac9f
36 lines
930 B
Python
36 lines
930 B
Python
# dialect.py
|
|
#
|
|
# Copyright 2016 Facebook, Inc.
|
|
#
|
|
# This software may be used and distributed according to the terms of the
|
|
# GNU General Public License version 2 or any later version.
|
|
|
|
"""replace terms with more widely used equivalents
|
|
|
|
With this extension enabled, some terms will be replaced by their more
|
|
well-known equivalents. Namely, "changeset" will be replaced by "commit".
|
|
"""
|
|
|
|
testedwith = "ships-with-fb-hgext"
|
|
|
|
from mercurial import extensions, i18n
|
|
|
|
|
|
def _ugettext(orig, message):
|
|
if orig:
|
|
message = orig(message)
|
|
message = message.replace("changeset", "commit")
|
|
return message
|
|
|
|
|
|
def _ungettext(orig, singular, plural, count):
|
|
if orig:
|
|
message = orig(singular, plural, count)
|
|
message = message.replace("changeset", "commit")
|
|
return message
|
|
|
|
|
|
def uisetup(ui):
|
|
extensions.wrapfunction(i18n, "_ugettext", _ugettext)
|
|
extensions.wrapfunction(i18n, "_ungettext", _ungettext)
|