Skip to content

Commit

Permalink
Merge pull request #15 from plone/maurits-recursive-translate-simplify
Browse files Browse the repository at this point in the history
Remove unneeded code from recursiveTranslate
  • Loading branch information
davisagli authored Dec 10, 2024
2 parents b540f36 + 5747d5f commit 494d29a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
17 changes: 8 additions & 9 deletions Products/validation/i18n.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from zope.i18n import translate
from zope.i18nmessageid import Message
from zope.i18nmessageid import MessageFactory


Expand All @@ -12,15 +11,15 @@ def safe_unicode(value):

def recursiveTranslate(message, **kwargs):
"""translates also the message mappings before translating the message.
if kwargs['REQUEST'] is None, return the message untranslated
"""
request = kwargs.get("REQUEST", None)
if kwargs['REQUEST'] is None, return the message untranslated
map = message.mapping
if map:
for key in map.keys():
if isinstance(map[key], Message):
map[key] = translate(map[key], context=request)
Actually, recursive translation has been built into zope.i18n 3.5.0,
which was already released in 2008. See
https://github.com/zopefoundation/zope.i18n/blob/master/CHANGES.rst#350-2008-07-10
So we can simply call the translate function.
This avoids a TypeError in Zope 5.11+, as `map[key]` is immutable there.
"""
request = kwargs.get("REQUEST", None)
return translate(message, context=request)
3 changes: 3 additions & 0 deletions news/70.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Remove unneeded code from ``recursiveTranslate`` that broke with latest Zope 5.11.
``zope.i18n`` already supports recursive translation out of the box since 2008.
[maurits]

0 comments on commit 494d29a

Please sign in to comment.