[PATCH 1 of 4] i18n: add support for plural forms, introduce ngettext

Andrei Polushin polushin at gmail.com
Mon Dec 19 17:38:52 CST 2011


20.12.2011 6:02, Andrei Polushin wrote:
> +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)

This could be further enhanced for compatibility with those 'witless morons'
that parse the existing output of Mercurial in plural form:

     u = t.ungettext(singular, plural, n)
     encoded = _encode(u, message)
     if n == 1 and encoded == singular:
         encoded = plural
     return encoded

Perhaps, there could be a configuration setting, say 'plurals = true' to
turn compatibility mode off.

I'll recent the patch if either solution is acceptable.

-- 
Andrei Polushin


More information about the Mercurial-devel mailing list