Skip to content

Commit

Permalink
Explicitly not support plural messages though fulfilling the interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
sallner committed Oct 7, 2020
1 parent 7ea5820 commit f6e672e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ CHANGES
their old locations in zope.component.interfaces instead of their current
locations in zope.interface.interfaces.

- Add compatibility with ``zope.i18n >= 4.7``. We fulfil the interface for
plural messages now, although we do not provide any implementation. This is
documented and raises NotImplementedError.


4.0.0 (2017-05-25)
------------------
Expand Down
30 changes: 29 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
=============
zope.app.i18n
=============

.. image:: https://img.shields.io/pypi/v/zope.app.i18n.svg
:target: https://pypi.python.org/pypi/zope.app.i18n/
:alt: Latest release

.. image:: https://img.shields.io/pypi/pyversions/zope.app.i18n.svg
:target: https://pypi.org/project/zope.app.i18n/
:alt: Supported Python versions

.. image:: https://travis-ci.org/zopefoundation/zope.app.i18n.svg?branch=master
:target: https://travis-ci.org/zopefoundation/zope.app.i18n

.. image:: https://coveralls.io/repos/github/zopefoundation/zope.app.i18n/badge.svg?branch=master
:target: https://coveralls.io/github/zopefoundation/zope.app.i18n?branch=master

Summary
-------

This package provides placeful persistent translation domains and
message catalogs along with ZMI views for managing them.
message catalogs along with ZMI views for managing them.

Caveats
-------

Currently this integration does not support the feature of plural messages
which is supported by the underlying ``zope.i18n`` library. In case you need
this feature, please discuss this in the issue tracker in the repository.
4 changes: 4 additions & 0 deletions src/zope/app/i18n/messagecatalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ def queryMessage(self, id, default=None):

def getPluralMessage(self, singular, plural, n):
'See `IMessageCatalog`'
# Plural messages are not supported yet. Please report an issue kn
# github in case you want to implement this feature.
raise NotImplementedError

def queryPluralMessage(self, singular, plural, n, dft1=None, dft2=None):
'See `IMessageCatalog`'
# Plural messages are not supported yet. Please report an issue kn
# github in case you want to implement this feature.
raise NotImplementedError

def getIdentifier(self):
Expand Down
17 changes: 17 additions & 0 deletions src/zope/app/i18n/tests/test_translationdomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,23 @@ def test_translate(self):
target_language='de'),
'Guten Tag!')

def test_translate__2(self):
"""It raises a NotImplementedError in case of plural messages."""
with self.assertRaises(NotImplementedError) as err:
self.trans1.translate('some text', msgid_plural="some texts")
with self.assertRaises(NotImplementedError) as err2:
self.trans1.translate('some text', default_plural="some texts")
with self.assertRaises(NotImplementedError) as err3:
self.trans1.translate('some text', number="some texts")

self.assertEqual(
str(err.exception), 'Plural messages are not supported yet')
self.assertEqual(
str(err2.exception), 'Plural messages are not supported yet')
self.assertEqual(
str(err3.exception), 'Plural messages are not supported yet')


def test_suite():
return unittest.TestSuite((
unittest.defaultTestLoader.loadTestsFromName(__name__),
Expand Down
5 changes: 5 additions & 0 deletions src/zope/app/i18n/translationdomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ def translate(self, msgid, mapping=None, context=None,
target_language=None, default=None, msgid_plural=None,
default_plural=None, number=None):
"""See interface `ITranslationDomain`"""
if any((default_plural, msgid_plural, number)):
# Plural messages are not supported yet. Please report an issue kn
# github in case you want to implement this feature.
raise NotImplementedError('Plural messages are not supported yet')

if target_language is None and context is not None:
avail_langs = self.getAvailableLanguages()
# Let's negotiate the language to translate to. :)
Expand Down

0 comments on commit f6e672e

Please sign in to comment.