Commit 6fe81228 authored by Valentin Benozillo's avatar Valentin Benozillo

erp5_hal_json_style: Fix missing translation when validator return error

parent 19645b96
...@@ -2107,7 +2107,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -2107,7 +2107,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
# Include cell error text in case of form validation # Include cell error text in case of form validation
if field_errors.has_key('%s_%s' % (editable_field.id, brain_uid)): if field_errors.has_key('%s_%s' % (editable_field.id, brain_uid)):
contents_item[select]['field_gadget_param']["error_text"] = \ contents_item[select]['field_gadget_param']["error_text"] = \
field_errors['%s_%s' % (editable_field.id, brain_uid)].error_text Base_translateString(field_errors['%s_%s' % (editable_field.id, brain_uid)].error_text)
# Do not generate link for empty value, as it will not be clickable in UI # Do not generate link for empty value, as it will not be clickable in UI
......
  • this seems very similar to 4e12f94c

    maybe we forgot to update this one as well. The translation of validation messages in ERP5JS is not tested yet ?

    In any case, we should probably use the getMessage API here as well.

    /cc @georgios.dagkakis @romain

  • I'm fixing test now, I will try to change to getMessage thanks Jérome

  • Thanks @valentin 🙏

  • Indeed, we should also make sure that things are not translated twice (and get translation of translation in Localizer).

    But I do not understand why 4e12f94c was not already enough in this case, I think it should be applied in all error message.

  • Indeed, we should also make sure that things are not translated twice (and get translation of translation in Localizer).

    Yes, this might be something we could cover in tests one day, with an approach like this:

    diff --git a/product/Localizer/Localizer.py b/product/Localizer/Localizer.py
    index a199acd6a2..494787241a 100644
    --- a/product/Localizer/Localizer.py
    +++ b/product/Localizer/Localizer.py
    @@ -38,6 +38,12 @@ from .utils import lang_negotiator
     from .LanguageManager import LanguageManager
     
     
    +import six
    +class TranslatedString(six.text_type):
    +  """A message that was already translated.
    +  """
    +  pass
    +
     
     # Constructors
     manage_addLocalizerForm = LocalDTMLFile('ui/Localizer_add', globals())
    @@ -280,7 +286,8 @@ class Localizer(LanguageManager, Folder):
             assert not args
             if lang is not None:
                 kw['target_language'] = lang
    -        return translate(to_unicode(msgid), domain=domain, **kw)
    +        assert not isinstance(msgid, TranslatedString)
    +        return TranslatedString(translate(to_unicode(msgid), domain=domain, **kw))
     
     InitializeClass(Localizer)

    ( it would be much more complicated, it's just a patch to explain the idea )

    But I do not understand why 4e12f94c was not already enough in this case, I think it should be applied in all error message.

    I don't know either

Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment