From bd33756008fe7ab6e3a673bc9ebb5691b8b2896a Mon Sep 17 00:00:00 2001 From: davisagli Date: Tue, 10 Dec 2024 09:45:17 -0800 Subject: [PATCH] [fc] Repository: Products.validation Branch: refs/heads/main Date: 2024-12-10T13:58:27+01:00 Author: Maurits van Rees (mauritsvanrees) Commit: https://github.com/plone/Products.validation/commit/5747d5f8e6282321fa63e9139c7be5042d9a9ceb Remove unneeded code from ``recursiveTranslate`` that broke with latest Zope 5.11. ``zope.i18n`` already supports recursive translation out of the box since 2008. See https://github.com/plone/Products.validation/pull/14#discussion_r1878046252 Files changed: A news/70.bugfix M Products/validation/i18n.py Repository: Products.validation Branch: refs/heads/main Date: 2024-12-10T09:45:17-08:00 Author: David Glick (davisagli) Commit: https://github.com/plone/Products.validation/commit/494d29a1eceff4aa6de9ce4078f7380816880327 Merge pull request #15 from plone/maurits-recursive-translate-simplify Remove unneeded code from recursiveTranslate Files changed: A news/70.bugfix M Products/validation/i18n.py --- last_commit.txt | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/last_commit.txt b/last_commit.txt index 4d1ff33c4f..eae83a6ed0 100644 --- a/last_commit.txt +++ b/last_commit.txt @@ -1,46 +1,38 @@ -Repository: plone.base +Repository: Products.validation -Branch: refs/heads/1.x -Date: 2024-12-06T23:15:59+01:00 +Branch: refs/heads/main +Date: 2024-12-10T13:58:27+01:00 Author: Maurits van Rees (mauritsvanrees) -Commit: https://github.com/plone/plone.base/commit/fcd4d3327c99589c56fa1624f1714889a6c7c6c1 +Commit: https://github.com/plone/Products.validation/commit/5747d5f8e6282321fa63e9139c7be5042d9a9ceb -Fixed tests when using Zope 5.11. +Remove unneeded code from ``recursiveTranslate`` that broke with latest Zope 5.11. -In one test we got a `mappingproxy` instead of a dictionary: +``zope.i18n`` already supports recursive translation out of the box since 2008. -``` -File "...plone.base-2.0.1-py3.10.egg/plone/base/tests/messages.rst", line 39, in messages.rst -Failed example: - msg.mapping -Expected: - {'name': 'Plone'} -Got: - mappingproxy({'name': 'Plone'}) -``` +See https://github.com/plone/Products.validation/pull/14#discussion_r1878046252 Files changed: -A news/956.tests -M src/plone/base/tests/messages.rst +A news/70.bugfix +M Products/validation/i18n.py -b"diff --git a/news/956.tests b/news/956.tests\nnew file mode 100644\nindex 0000000..fc57308\n--- /dev/null\n+++ b/news/956.tests\n@@ -0,0 +1,3 @@\n+Fixed tests when using Zope 5.11.\n+In one test we got a `mappingproxy` instead of a dictionary.\n+[maurits]\ndiff --git a/src/plone/base/tests/messages.rst b/src/plone/base/tests/messages.rst\nindex 2187c65..f6ec452 100644\n--- a/src/plone/base/tests/messages.rst\n+++ b/src/plone/base/tests/messages.rst\n@@ -36,7 +36,7 @@ And at last there is the possibility of variable substitution:\n >>> msg.default\n 'Hello ${name}'\n \n- >>> msg.mapping\n+ >>> dict(msg.mapping)\n {'name': 'Plone'}\n \n Messages with translation service set up\n" +b'diff --git a/Products/validation/i18n.py b/Products/validation/i18n.py\nindex 8e2f6a8..480179e 100644\n--- a/Products/validation/i18n.py\n+++ b/Products/validation/i18n.py\n@@ -1,5 +1,4 @@\n from zope.i18n import translate\n-from zope.i18nmessageid import Message\n from zope.i18nmessageid import MessageFactory\n \n \n@@ -12,15 +11,15 @@ def safe_unicode(value):\n \n def recursiveTranslate(message, **kwargs):\n """translates also the message mappings before translating the message.\n- if kwargs[\'REQUEST\'] is None, return the message untranslated\n- """\n \n- request = kwargs.get("REQUEST", None)\n+ if kwargs[\'REQUEST\'] is None, return the message untranslated\n \n- map = message.mapping\n- if map:\n- for key in map.keys():\n- if isinstance(map[key], Message):\n- map[key] = translate(map[key], context=request)\n+ Actually, recursive translation has been built into zope.i18n 3.5.0,\n+ which was already released in 2008. See\n+ https://github.com/zopefoundation/zope.i18n/blob/master/CHANGES.rst#350-2008-07-10\n \n+ So we can simply call the translate function.\n+ This avoids a TypeError in Zope 5.11+, as `map[key]` is immutable there.\n+ """\n+ request = kwargs.get("REQUEST", None)\n return translate(message, context=request)\ndiff --git a/news/70.bugfix b/news/70.bugfix\nnew file mode 100644\nindex 0000000..cbc3a55\n--- /dev/null\n+++ b/news/70.bugfix\n@@ -0,0 +1,3 @@\n+Remove unneeded code from ``recursiveTranslate`` that broke with latest Zope 5.11.\n+``zope.i18n`` already supports recursive translation out of the box since 2008.\n+[maurits]\n' -Repository: plone.base +Repository: Products.validation -Branch: refs/heads/1.x -Date: 2024-12-10T12:23:34+01:00 -Author: Maurits van Rees (mauritsvanrees) -Commit: https://github.com/plone/plone.base/commit/52285cf96e94519b1e8912dcaa3f3ae7f4826edb +Branch: refs/heads/main +Date: 2024-12-10T09:45:17-08:00 +Author: David Glick (davisagli) +Commit: https://github.com/plone/Products.validation/commit/494d29a1eceff4aa6de9ce4078f7380816880327 -Merge pull request #74 from plone/maurits-mappingproxy-1x +Merge pull request #15 from plone/maurits-recursive-translate-simplify -Fixed tests when using Zope 5.11. [1.x, second try] +Remove unneeded code from recursiveTranslate Files changed: -A news/956.tests -M src/plone/base/tests/messages.rst +A news/70.bugfix +M Products/validation/i18n.py -b"diff --git a/news/956.tests b/news/956.tests\nnew file mode 100644\nindex 0000000..fc57308\n--- /dev/null\n+++ b/news/956.tests\n@@ -0,0 +1,3 @@\n+Fixed tests when using Zope 5.11.\n+In one test we got a `mappingproxy` instead of a dictionary.\n+[maurits]\ndiff --git a/src/plone/base/tests/messages.rst b/src/plone/base/tests/messages.rst\nindex 2187c65..f6ec452 100644\n--- a/src/plone/base/tests/messages.rst\n+++ b/src/plone/base/tests/messages.rst\n@@ -36,7 +36,7 @@ And at last there is the possibility of variable substitution:\n >>> msg.default\n 'Hello ${name}'\n \n- >>> msg.mapping\n+ >>> dict(msg.mapping)\n {'name': 'Plone'}\n \n Messages with translation service set up\n" +b'diff --git a/Products/validation/i18n.py b/Products/validation/i18n.py\nindex 8e2f6a8..480179e 100644\n--- a/Products/validation/i18n.py\n+++ b/Products/validation/i18n.py\n@@ -1,5 +1,4 @@\n from zope.i18n import translate\n-from zope.i18nmessageid import Message\n from zope.i18nmessageid import MessageFactory\n \n \n@@ -12,15 +11,15 @@ def safe_unicode(value):\n \n def recursiveTranslate(message, **kwargs):\n """translates also the message mappings before translating the message.\n- if kwargs[\'REQUEST\'] is None, return the message untranslated\n- """\n \n- request = kwargs.get("REQUEST", None)\n+ if kwargs[\'REQUEST\'] is None, return the message untranslated\n \n- map = message.mapping\n- if map:\n- for key in map.keys():\n- if isinstance(map[key], Message):\n- map[key] = translate(map[key], context=request)\n+ Actually, recursive translation has been built into zope.i18n 3.5.0,\n+ which was already released in 2008. See\n+ https://github.com/zopefoundation/zope.i18n/blob/master/CHANGES.rst#350-2008-07-10\n \n+ So we can simply call the translate function.\n+ This avoids a TypeError in Zope 5.11+, as `map[key]` is immutable there.\n+ """\n+ request = kwargs.get("REQUEST", None)\n return translate(message, context=request)\ndiff --git a/news/70.bugfix b/news/70.bugfix\nnew file mode 100644\nindex 0000000..cbc3a55\n--- /dev/null\n+++ b/news/70.bugfix\n@@ -0,0 +1,3 @@\n+Remove unneeded code from ``recursiveTranslate`` that broke with latest Zope 5.11.\n+``zope.i18n`` already supports recursive translation out of the box since 2008.\n+[maurits]\n'