Skip to content

Commit

Permalink
Added comments, added missing methods in interface. Added specific br…
Browse files Browse the repository at this point in the history
…anch for zope.i18nmessageid in travis.
  • Loading branch information
trollfot committed Oct 18, 2018
1 parent fba2fd4 commit 14be9f1
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ install:
- pip install -U pip setuptools
- pip install -U coverage coveralls
- pip install -U -e .[test,docs]
- pip install -e git+git@github.com:minddistrict/zope.i18nmessageid.git@CB-556-FR-translation-with-C#egg=zope.i18nmessageid
script:
- coverage run -m zope.testrunner --test-path=src
- coverage run -a -m sphinx -b doctest -d docs/_build/doctrees docs docs/_build/doctest
Expand Down
1 change: 0 additions & 1 deletion src/zope/i18n/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ def interpolate(text, mapping=None):
>>> print(interpolate(
... u"This is $name $version. $unknown $$name $${version}.", mapping))
This is Zope 3. $unknown $$name $${version}.
>>> print(interpolate(u"This is ${name}"))
Expand Down
7 changes: 7 additions & 0 deletions src/zope/i18n/gettextmessagecatalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ def ungettext(self, singular, plural, n):


def plural_formatting(func):
"""This decorator interpolates the `%d` possibly present in the string.
This interpolation marker is usally present for plurals.
Example: `There are %d apples`.
Please note that the interpolation can be done, alternatively,
using the mapping. This is only present as a conveniance.
"""
@wraps(func)
def pformat(catalog, singular, plural, n, *args, **kwargs):
msg = func(catalog, singular, plural, n, *args, **kwargs)
Expand Down
20 changes: 17 additions & 3 deletions src/zope/i18n/interfaces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,23 @@ def queryMessage(msgid, default=None):
If the message id is not found, default is returned.
"""

# FIX ME ADD PLURAL METHODS IF WE DECIDE TO KEEP THEM SEPARATED FROM
# THE SINGULAR METHODS.

def getPluralMessage(self, singular, plural, n):
"""Get the appropriate text for the given message id and the
plural id.
An exception is raised if nothing was found.
"""

def queryPluralMessage(singular, plural, n, dft1=None, dft2=None):
"""Look for the appropriate text for the given message id and the
plural id.
If `n` is evaluated as a singular and the id is not found,
`dft1` is returned.
If `n` is evaluated as a plural and the plural id is not found,
`dft2` is returned.
"""

language = TextLine(
title=u"Language",
description=u"The language the catalog translates to.",
Expand Down
Binary file added src/zope/i18n/tests/pl-default.mo
Binary file not shown.
9 changes: 0 additions & 9 deletions src/zope/i18n/tests/test_plurals.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,3 @@ def test_PolishPlurals(self):
self.assertEqual(catalog.getPluralMessage(
'There is one file.', 'There are %d files.', 28),
"Istnieją 28 plików.")


def test_suite():
return unittest.TestSuite((
unittest.makeSuite(TestPlurals),
))

if __name__ == '__main__':
unittest.main(defaultTest='test_suite')

0 comments on commit 14be9f1

Please sign in to comment.