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())
Comment | File | Size | Author |
---|---|---|---|
#14 | Screenshot 2019-10-14 at 2.19.33 PM.png | 65.05 KB | naresh_bavaskar |
#10 | 3076778-10.patch | 4.07 KB | nikunjkotecha |
|
Comments
Comment #2
HeikkiY CreditAttribution: HeikkiY commentedComment #3
HeikkiY CreditAttribution: HeikkiY commentedComment #4
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe 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?
Comment #5
HeikkiY CreditAttribution: HeikkiY commentedI 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.
Comment #6
HeikkiY CreditAttribution: HeikkiY commentedComment #7
HeikkiY CreditAttribution: HeikkiY commentedComment #8
nikunjkotechaI 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.
Comment #9
nikunjkotechaThis 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
Comment #10
nikunjkotechaAdding messages from backend and removed duplicate code execution in JavaScript.
Comment #11
ambuj_gupta CreditAttribution: ambuj_gupta at QED42 commentedComment #12
naresh_bavaskarComment #13
nikunjkotechaComment #14
naresh_bavaskarThe above patch is worked for me, 3076778-10.patch (#10) @nikunjkotech.
Thanks
Comment #16
nikunjkotechaThanks everyone.