summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSouheil CHELFOUH <trollfot@gmail.com>2018-10-18 11:56:43 +0200
committerSouheil CHELFOUH <trollfot@gmail.com>2018-10-18 11:56:43 +0200
commit6f3c31ad3bae07996c7df60afd79cab482e463ff (patch)
tree1a6dca518cc1e0793058cff47701acf9afed1b74
parent14be9f16e5df448b89c02b5b37d6c07deb8a778f (diff)
downloadzope-i18n-6f3c31ad3bae07996c7df60afd79cab482e463ff.tar.gz
Corrected interpolation marker comments and added tests for plurals using floats.
-rw-r--r--src/zope/i18n/gettextmessagecatalog.py4
-rw-r--r--src/zope/i18n/tests/en-default.mobin478 -> 734 bytes
-rw-r--r--src/zope/i18n/tests/en-default.po10
-rw-r--r--src/zope/i18n/tests/test_plurals.py34
4 files changed, 46 insertions, 2 deletions
diff --git a/src/zope/i18n/gettextmessagecatalog.py b/src/zope/i18n/gettextmessagecatalog.py
index ff9ef71..675c7f2 100644
--- a/src/zope/i18n/gettextmessagecatalog.py
+++ b/src/zope/i18n/gettextmessagecatalog.py
@@ -32,9 +32,9 @@ class _KeyErrorRaisingFallback(object):
def plural_formatting(func):
- """This decorator interpolates the `%d` possibly present in the string.
+ """This decorator interpolates the possible formatting marker.
This interpolation marker is usally present for plurals.
- Example: `There are %d apples`.
+ Example: `There are %d apples` or `They have %s pies.'
Please note that the interpolation can be done, alternatively,
using the mapping. This is only present as a conveniance.
diff --git a/src/zope/i18n/tests/en-default.mo b/src/zope/i18n/tests/en-default.mo
index 3e9dc9e..1ee7c89 100644
--- a/src/zope/i18n/tests/en-default.mo
+++ b/src/zope/i18n/tests/en-default.mo
Binary files differ
diff --git a/src/zope/i18n/tests/en-default.po b/src/zope/i18n/tests/en-default.po
index fc45a11..2c75c64 100644
--- a/src/zope/i18n/tests/en-default.po
+++ b/src/zope/i18n/tests/en-default.po
@@ -18,3 +18,13 @@ msgid "There is one file."
msgid_plural "There are %d files."
msgstr[0] "There is one file."
msgstr[1] "There are %d files."
+
+msgid "The item is rated 1/5 star."
+msgid_plural "The item is rated %s/5 stars."
+msgstr[0] "The item is rated 1/5 star."
+msgstr[1] "The item is rated %s/5 stars."
+
+msgid "There is %d chance."
+msgid_plural "There are %f chances."
+msgstr[0] "There is %d chance."
+msgstr[1] "There are %f chances."
diff --git a/src/zope/i18n/tests/test_plurals.py b/src/zope/i18n/tests/test_plurals.py
index 2020f85..50e192d 100644
--- a/src/zope/i18n/tests/test_plurals.py
+++ b/src/zope/i18n/tests/test_plurals.py
@@ -98,3 +98,37 @@ class TestPlurals(unittest.TestCase):
self.assertEqual(catalog.getPluralMessage(
'There is one file.', 'There are %d files.', 28),
"Istnieją 28 plików.")
+
+ def test_floater(self):
+ """Test with the number being a float.
+ We can use %f or %s to make sure it works.
+ """
+ catalog = self._getMessageCatalog('en')
+ self.assertEqual(catalog.language, 'en')
+
+ # It's cast to integer because of the %d in the translation string.
+ self.assertEqual(catalog.getPluralMessage(
+ 'There is one file.', 'There are %d files.', 1.0),
+ 'There is one file.')
+
+ self.assertEqual(catalog.getPluralMessage(
+ 'There is one file.', 'There are %d files.', 3.5),
+ 'There are 3 files.')
+
+ # It's cast to a string because of the %s in the translation string.
+ self.assertEqual(catalog.getPluralMessage(
+ 'The item is rated 1/5 star.',
+ 'The item is rated %s/5 stars.', 3.5),
+ 'The item is rated 3.5/5 stars.')
+
+ # It's cast either to an int or a float because of the %s in
+ # the translation string.
+ self.assertEqual(catalog.getPluralMessage(
+ 'There is %d chance.',
+ 'There are %f chances.', 1.5),
+ 'There are 1.500000 chances.')
+
+ self.assertEqual(catalog.getPluralMessage(
+ 'There is %d chance.',
+ 'There are %f chances.', 3.5),
+ 'There are 3.500000 chances.')