diff options
author | Souheil CHELFOUH <trollfot@gmail.com> | 2018-10-18 11:04:02 +0200 |
---|---|---|
committer | Souheil CHELFOUH <trollfot@gmail.com> | 2018-10-18 11:04:02 +0200 |
commit | 14be9f16e5df448b89c02b5b37d6c07deb8a778f (patch) | |
tree | 51252539c2b3d98621c2a3523c856ab023d6e169 /src | |
parent | fba2fd42d458a1229bfd0f58967cb2c13e00a84b (diff) | |
download | zope-i18n-14be9f16e5df448b89c02b5b37d6c07deb8a778f.tar.gz |
Added comments, added missing methods in interface. Added specific branch for zope.i18nmessageid in travis.
Diffstat (limited to 'src')
-rw-r--r-- | src/zope/i18n/__init__.py | 1 | ||||
-rw-r--r-- | src/zope/i18n/gettextmessagecatalog.py | 7 | ||||
-rw-r--r-- | src/zope/i18n/interfaces/__init__.py | 20 | ||||
-rw-r--r-- | src/zope/i18n/tests/pl-default.mo | bin | 0 -> 570 bytes | |||
-rw-r--r-- | src/zope/i18n/tests/test_plurals.py | 9 |
5 files changed, 24 insertions, 13 deletions
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 Binary files differnew file mode 100644 index 0000000..37b73fe --- /dev/null +++ b/src/zope/i18n/tests/pl-default.mo 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') |