Commit 0aeea3c4 authored by Georgios Dagkakis's avatar Georgios Dagkakis

Validation message translation

See merge request !1001
parents 1b11dd03 4e12f94c
Pipeline #13028 failed with stage
...@@ -1042,7 +1042,7 @@ def renderForm(traversed_document, form, response_dict, key_prefix=None, selecti ...@@ -1042,7 +1042,7 @@ def renderForm(traversed_document, form, response_dict, key_prefix=None, selecti
try: try:
response_dict[field.id] = renderField(traversed_document, field, form, key_prefix=key_prefix, selection_params=selection_params, request_field=not use_relation_form_page_template) response_dict[field.id] = renderField(traversed_document, field, form, key_prefix=key_prefix, selection_params=selection_params, request_field=not use_relation_form_page_template)
if field_errors.has_key(field.id): if field_errors.has_key(field.id):
response_dict[field.id]["error_text"] = field_errors[field.id].error_text response_dict[field.id]["error_text"] = field_errors[field.id].getMessage(Base_translateString)
except AttributeError as error: except AttributeError as error:
# Do not crash if field configuration is wrong. # Do not crash if field configuration is wrong.
log("Field {} rendering failed because of {!s}".format(field.id, error), level=800) log("Field {} rendering failed because of {!s}".format(field.id, error), level=800)
......
...@@ -30,8 +30,7 @@ ...@@ -30,8 +30,7 @@
<div class="input" tal:content="structure python: html_tuple[1]" /> <div class="input" tal:content="structure python: html_tuple[1]" />
<span tal:condition="field_has_error" <span tal:condition="field_has_error"
class="error" class="error"
tal:content="python: field_errors[field_id].error_text" tal:content="python: field_errors[field_id].getMessage(here.Base_translateString)" />
i18n:translate="" i18n:domain="ui" />
<p class="clear" tal:condition="not:is_web_mode"></p> <p class="clear" tal:condition="not:is_web_mode"></p>
</tal:block> </tal:block>
</div> </div>
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
# from Products.Formulator.Errors import ValidationError, FormValidationError # from Products.Formulator.Errors import ValidationError, FormValidationError
from Products.PythonScripts.Utility import allow_class from Products.PythonScripts.Utility import allow_class
from AccessControl import ClassSecurityInfo
class FormValidationError(Exception): class FormValidationError(Exception):
...@@ -17,6 +18,8 @@ allow_class(FormValidationError) ...@@ -17,6 +18,8 @@ allow_class(FormValidationError)
class ValidationError(Exception): class ValidationError(Exception):
security = ClassSecurityInfo()
def __init__(self, error_key, field, error_text=None): def __init__(self, error_key, field, error_text=None):
Exception.__init__(self, error_key) Exception.__init__(self, error_key)
self.error_key = error_key self.error_key = error_key
...@@ -24,8 +27,18 @@ class ValidationError(Exception): ...@@ -24,8 +27,18 @@ class ValidationError(Exception):
self.field = field self.field = field
if error_text is not None: if error_text is not None:
self.error_text = error_text self.error_text = error_text
self.is_message_to_translate = False
else: else:
self.error_text = field.get_error_message(error_key) self.error_text = field.get_error_message(error_key)
self.is_message_to_translate = True
security.declarePublic('getMessage')
def getMessage(self, translation_service=None):
if not self.is_message_to_translate:
return self.error_text
if translation_service is None:
return self.error_text
return translation_service(self.error_text)
allow_class(ValidationError) allow_class(ValidationError)
......
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