Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set language in recaptcha - flask

I am trying to change the error message when the user forget to check the recaptcha checkbox. Even after set the language to pt, I am still receiving this message: The response parameter is missing.

from flask.ext.wtf import Form, RecaptchaField

recaptcha = RecaptchaField()

RECAPTCHA_PUBLIC_KEY = 'yyyy'
RECAPTCHA_PRIVATE_KEY = 'xxxx'
RECAPTCHA_PARAMETERS = {'hl': 'pt'}

-Language code from here

-Flask docs1 docs2 about recpacha

How can i change the language of these messages?

EDIT: Even after the upgrade to the last version of flask-wtforms, the error messages still are always in English. Only the labels change.

Relevant source code

like image 566
user2990084 Avatar asked Oct 20 '22 02:10

user2990084


1 Answers

I don't think it's possible with their current implementation:

https://github.com/lepture/flask-wtf/blob/8879e9827b0160776031bd06ef083b81282904e5/flask_wtf/recaptcha/widgets.py#L8

They have hardcoded URL to the library: https://www.google.com/recaptcha/api.js

But for different language settings there should be GET parameter passed in the recaptcha URL, for example: https://www.google.com/recaptcha/api.js?hl=ru

I've had to overwrite the field and validation manually for using different language settings.

like image 154
AnaPana Avatar answered Oct 21 '22 17:10

AnaPana