[PATCH 1 of 4] i18n: add support for plural forms, introduce ngettext
Andrei Polushin
polushin at gmail.com
Mon Dec 19 17:02:34 CST 2011
# HG changeset patch
# User Andrei Polushin <polushin at gmail.com>
# Date 1324152064 -25200
# Node ID 38b5e0c738797907c7ef6724079bbe87c67ed3cc
# Parent 21eb048edc19a9b78ae262d222c0de1f3ad6c4d2
i18n: add support for plural forms, introduce ngettext
diff -r 21eb048edc19 -r 38b5e0c73879 mercurial/i18n.py
--- a/mercurial/i18n.py Mon Dec 19 11:37:44 2011 +0100
+++ b/mercurial/i18n.py Sun Dec 18 03:01:04 2011 +0700
@@ -40,6 +40,21 @@
# Be careful not to translate the empty string -- it holds the
# meta data of the .po file.
u = u'\n\n'.join([p and t.ugettext(p) or '' for p in paragraphs])
+ return _encode(u, message)
+
+def ngettext(singular, plural, n):
+ if n == 1:
+ message = singular
+ else:
+ message = plural
+
+ if message is None or message == '':
+ return message
+
+ u = t.ungettext(singular, plural, n)
+ return _encode(u, message)
+
+def _encode(u, message):
try:
# encoding.tolocal cannot be used since it will first try to
# decode the Unicode string. Calling u.decode(enc) really
More information about the Mercurial-devel
mailing list