summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSouheil CHELFOUH <trollfot@gmail.com>2018-10-18 11:04:02 +0200
committerSouheil CHELFOUH <trollfot@gmail.com>2018-10-18 11:04:02 +0200
commit14be9f16e5df448b89c02b5b37d6c07deb8a778f (patch)
tree51252539c2b3d98621c2a3523c856ab023d6e169
parentfba2fd42d458a1229bfd0f58967cb2c13e00a84b (diff)
downloadzope-i18n-14be9f16e5df448b89c02b5b37d6c07deb8a778f.tar.gz
Added comments, added missing methods in interface. Added specific branch for zope.i18nmessageid in travis.
-rw-r--r--.travis.yml1
-rw-r--r--src/zope/i18n/__init__.py1
-rw-r--r--src/zope/i18n/gettextmessagecatalog.py7
-rw-r--r--src/zope/i18n/interfaces/__init__.py20
-rw-r--r--src/zope/i18n/tests/pl-default.mobin0 -> 570 bytes
-rw-r--r--src/zope/i18n/tests/test_plurals.py9
6 files changed, 25 insertions, 13 deletions
diff --git a/.travis.yml b/.travis.yml
index b2ff47d..61aa8db 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -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
diff --git a/src/zope/i18n/__init__.py b/src/zope/i18n/__init__.py
index 854223c..5f7d775 100644
--- a/src/zope/i18n/__init__.py
+++ b/src/zope/i18n/__init__.py
@@ -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}"))
diff --git a/src/zope/i18n/gettextmessagecatalog.py b/src/zope/i18n/gettextmessagecatalog.py
index 99f1951..ff9ef71 100644
--- a/src/zope/i18n/gettextmessagecatalog.py
+++ b/src/zope/i18n/gettextmessagecatalog.py
@@ -32,6 +32,13 @@ class _KeyErrorRaisingFallback(object):
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)
diff --git a/src/zope/i18n/interfaces/__init__.py b/src/zope/i18n/interfaces/__init__.py
index 5935fc1..11d8c21 100644
--- a/src/zope/i18n/interfaces/__init__.py
+++ b/src/zope/i18n/interfaces/__init__.py
@@ -67,9 +67,23 @@ class IMessageCatalog(Interface):
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.",
diff --git a/src/zope/i18n/tests/pl-default.mo b/src/zope/i18n/tests/pl-default.mo
new file mode 100644
index 0000000..37b73fe
--- /dev/null
+++ b/src/zope/i18n/tests/pl-default.mo
Binary files differ
diff --git a/src/zope/i18n/tests/test_plurals.py b/src/zope/i18n/tests/test_plurals.py
index a0ca9bf..2020f85 100644
--- a/src/zope/i18n/tests/test_plurals.py
+++ b/src/zope/i18n/tests/test_plurals.py
@@ -98,12 +98,3 @@ class TestPlurals(unittest.TestCase):
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')