zopefoundation / zope.i18n

APIs and data related to internationalization and localization.
Other
2 stars 13 forks source link

Support i18n plural forms #5

Closed tseaver closed 6 years ago

tseaver commented 9 years ago

In https://bugs.launchpad.net/zope.i18n/+bug/161985, @ccomb reported:

Some languages use the plural form for zero (English, German, Dutch, Italian, Spanish, Portuguese):

This is generated by the ISized adapter of containers :

  • "0 items"
  • "1 item"
  • "2 items"

Regardless of whether this is logical or not to have a plural form for something below 1 :), other languages like French use the plural form only for numbers greater than 1 :

  • "0 élément"
  • "1 élément"
  • "2 élements"

This should be taken into account where applicable (at least on some ISized adapters)

@ctheune follwed up:

zope.i18n does not support plural forms, unfortunately, although it should. The way this is done right now is very hacky.

@strichter:

Could someone do some research on this? What deos it look like and is there a Python implementation for it? I am willing to do the necessary coding, if I get the info I need.

@ccomb:

Actually someone made me realize that "zero" is just a typical plural-form, and it can be handled as such. It should be sufficient to use the plural form fonctionnality of gettext where applicable. The string to translate should just be forked into as many plural forms as necessary, and the translators have to translate all these strings separately.

More details here: http://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html

@tmassman:

I added the plural form support in a separate branch: https://code.launchpad.net/~thomas-massmann/zope.i18n/plural. This code was mainly implemented during the 2012 Plonekonf in Munich.

It is already in "production" in a project I'm developing right now. Please note that zope.i18nmessageid needs to be taken from this branch to work: https://code.launchpad.net/~thomas-massmann/zope.i18nmessageid/plural.

Extracting plural messages is supported by xgettext by default. Zope tools like i18nduder have to be adjusted (they don't support ungettext right now). I already adjusted lingua by Wichert Akkerman (https://github.com/tmassman/lingua) - the pull request is still open.

trollfot commented 6 years ago

The work has been done and it has been released.

thomasmassmann commented 6 years ago

May I ask for an example on how to use the new plural implementation, especially which tool to use to extract the plural message ids, so that they are created based on the gettext standard (ngettext, ungettext)?