It seems that currently it is not possible to translate number field validation 100%.

If you for example input - or + sign to a number field, it gives the error "Please enter a valid number." which is not translated. Other Webform validation messages seem to have the data-msg attribute which is translated but this does not.

The input element has the following code when translated:
<input data-drupal-selector="edit-numero" data-msg-max="Kentän Numero tulee olla vähemmän kuin 10." data-msg-min="Kentän Numero arvon tulee olla suurempi kuin 5." data-msg-required="Numero on pakollinen" data-msg-step="Kentän Numero arvon tulee olla suurempi kuin 5, yksittäisen askelen ollessa 1." type="number" id="edit-numero" name="numero" value="" step="1" min="5" max="10" class="form-number required" required="required" aria-required="true">

I think it should also have a data message for the number validity. Attached is an example webform with the problem.

Steps to reproduce

* Configure a site with at-least two languages (fr preferred as example webform config has fr)
* Enable user interface translation
* Enable webform
* Import webform attached in #2 or create a webform with number field
* Try to translate the error message "Please enter a valid number."

Actual (before applying patch):
* Error message is not available for translation even after seeing that in frontend (message is passed through Drupal.t())

Expected (after applying patch):
* Error message is available for translation after seeing that in frontend once (message is passed through t())

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

HeikkiY created an issue. See original summary.

HeikkiY’s picture

Project: Clientside Validation » Webform
Version: 8.x-1.x-dev » 8.x-5.x-dev
Component: Webform Validation » Code
Issue summary: View changes
FileSize
4.21 KB
HeikkiY’s picture

Issue summary: View changes
jrockowitz’s picture

Status: Active » Postponed (maintainer needs more info)

The Webform module does not add the data-msg-* attributes. I am pretty sure the 'Please enter a valid number.' message is either coming from the browser or a different contributed module.

Can you please include a screenshot of where you are seeing the untranslated message?

HeikkiY’s picture

I think the culprit is Clientside validation. I thought those data-msg-* attributes were coming from Webform but I think this can be moved back to Clientside validation module. The error message is coming from the clientside validation errors.

HeikkiY’s picture

Project: Webform » Clientside Validation
Version: 8.x-5.x-dev » 8.x-1.x-dev
HeikkiY’s picture

Status: Postponed (maintainer needs more info) » Active
nikunjkotecha’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev

I confirm the issue and it is not limited to this error or webforms only. Messages that come from the library (jquery.validate) are not translated as they are not passed through Drupal.t()

Looking for a way to fix this.

nikunjkotecha’s picture

This seems not possible as of today, we will need to translate the strings and pass them to JS from Backend only

see https://www.drupal.org/project/drupal/issues/2972582

nikunjkotecha’s picture

Status: Active » Needs review
FileSize
4.07 KB

Adding messages from backend and removed duplicate code execution in JavaScript.

ambuj_gupta’s picture

Assigned: Unassigned » ambuj_gupta
naresh_bavaskar’s picture

nikunjkotecha’s picture

Issue summary: View changes
naresh_bavaskar’s picture

Assigned: naresh_bavaskar » Unassigned
Status: Needs review » Reviewed & tested by the community
FileSize
65.05 KB

The above patch is worked for me, 3076778-10.patch (#10) @nikunjkotech.

Thanks

  • nikunjkotecha committed 95b7ebb on 8.x-2.x
    Issue #3076778 by nikunjkotecha, HeikkiY, naresh_bavaskar: Number field...
nikunjkotecha’s picture

Status: Reviewed & tested by the community » Fixed

Thanks everyone.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.