-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to change the language of the recaptcha? #30
Comments
Hello @loicteixeira and @benoitvogel is there a way to fix issue? I want to force the language of the recaptcha widget to be equal to my |
Since the original authors are unresponsive I'll provide a hacky solution ; I couldn't make this work otherwise: First of all, copy the files Now, you should properly override the To resolve that, I'm adding the following in my form_page before rendering the form:
then, in the
This works fine and when I change the language it will display the proper messages from google. Notice that I don't pass the |
Sorry for the late reply, I do not work at Springload anymore and therefore I wasn't paying much attention to this repository. While I cannot guarantee it would be merged, I'd advise you to propose a pull request so it can be fixed on the package directly. |
@spapas Great, thank you! |
@Ratatam123 you're welcome! @loicteixeira no problem! I don't like to create a PR for these changes because they are hacky; I think the correct way to implement that is to somehow allow defining the However I guess the hacky solution could be used for now by any people that need this functionality until it's impmented properly! |
I had this same issue and solved it in the following way. If you have a class for the form that inherits from class FormPage(WagtailCaptchaEmailForm):
pass Then firstly create a custom formbuilder which inherits from WagtailCaptchaFormBuilder, and override the (this is reimplementing this method https://github.com/springload/wagtail-django-recaptcha/blob/da39697d16499658f2ef954bfb98baae34df119b/wagtailcaptcha/forms.py#L16 but we are setting class TranslationWagtailCaptchaFormBuilder(WagtailCaptchaFormBuilder):
@property
def formfields(self):
fields = super(WagtailCaptchaFormBuilder, self).formfields
field = ReCaptchaField(label='')
field.widget.api_params["hl"] = translation.get_language()
fields[self.CAPTCHA_FIELD_NAME] = field
return fields Then in your original form simply override the form builder. class FormPage(WagtailCaptchaEmailForm):
form_builder = TranslationWagtailCaptchaFormBuilder There may be a better way of doing this, but this didn't seem overly hacky :-) |
Old issue, but you can supply the language code to the api_params keyword in the django_recaptcha widget. Eg: fields[self.CAPTCHA_FIELD_NAME] = ReCaptchaField(
widget=ReCaptchaV3(api_params={'hl': Locale.get_active().language_code})
) I've raised a suggestion (#54) to improve the flexibility and make widget config a lot easier. I'll make a PR if there's interest. |
Hello,
is there a simple way to change the language of the recaptcha?
(My case: My contactform-model so far simply inherits from WagtailCaptchaEmailForm)
The text was updated successfully, but these errors were encountered: