Lack of interest Option to specify CAPTCHA language

This suggestion has been closed automatically because it did not receive enough votes over an extended period of time. If you wish to see this, please search for an open suggestion and, if you don't find any, post a new one.

ivp

Active member
Since our forum is non-English, would like to force a specific language for CAPTCHA.

I understand that the implementation is the following:
We don't specify a specific language code so we're allowing Google to detect your language (which is presumably using the Accept-Language header, though it could be doing GeoIP).

The only way to specify CAPTCHA language currently is to manually edit files captcha.js/captcha.min.js, which is not ideal.
 
Upvote 1
This suggestion has been closed. Votes are no longer accepted.
The only way to specify CAPTCHA language currently is to manually edit files captcha.js/captcha.min.js, which is not ideal.
Did you try to replace
Code:
<xf:js src="xf/captcha.js" min="1" />

with

Code:
<xf:js src="xf/captcha.js" min="1" />

<xf:js>
(function ($, window, document, _undefined)
{
    "use strict";

    XF.ReCaptcha = XF.extend(XF.ReCaptcha, {
        init: function()
        {
            if (!this.options.sitekey)
            {
                return;
            }

            var $form = this.$target.closest('form');

            if (this.options.invisible)
            {
                var $reCaptchaTarget = $('<div />'),
                    $formRow = this.$target.closest('.formRow');

                $formRow.hide();
                $formRow.after($reCaptchaTarget);
                this.$reCaptchaTarget = $reCaptchaTarget;

                $form.on('ajax-submit:before', XF.proxy(this, 'beforeSubmit'));
            }
            else
            {
                this.$reCaptchaTarget = this.$target;
            }

            $form.on('ajax-submit:error ajax-submit:always', XF.proxy(this, 'reload'));

            if (window.grecaptcha)
            {
                this.create();
            }
            else
            {
                XF.ReCaptcha.Callbacks.push(XF.proxy(this, 'create'));

                $.ajax({
                    url: 'https://www.recaptcha.net/recaptcha/api.js?onload=XFReCaptchaCallback&render=explicit&hl=<languagecode>',
                    dataType: 'script',
                    cache: true,
                    global: false
                });
            }
        },
    });
} (jQuery, window, document));
</xf:js>

in template captcha_recaptcha ?
 
That's interesting solution, thank you @Kirby.

Do you have similar code for hCaptcha, since it is the default provider:
 
The code does not work. Console displays Uncaught TypeError: Cannot read properties of undefined (reading 'push') in line XF.ReCaptcha.Callbacks.push(XF.proxy(this, 'create'));

Here is the fix for hCaptcha:

In template captcha_hcaptcha replace:
Code:
<xf:js src="xf/captcha.js" min="1" />
with:
Code:
<xf:js src="xf/captcha.js" min="1" />

<xf:js>
	XF.Element.extend('h-captcha', {
		init: function()
		{
			if (!this.options.sitekey)
			{
				return;
			}

			var $form = this.$target.closest('form');

			$form.on('ajax-submit:error ajax-submit:always', XF.proxy(this, 'reload'));

			if (this.options.invisible)
			{
				var $hCaptchaTarget = $('<div />'),
					$formRow = this.$target.closest('.formRow');

				$formRow.hide();
				$formRow.after($hCaptchaTarget);
				this.$hCaptchaTarget = $hCaptchaTarget;

				$form.on('ajax-submit:before', XF.proxy(this, 'beforeSubmit'));
			}
			else
			{
				this.$hCaptchaTarget = this.$target;
			}

			if (window.hcaptcha)
			{
				this.create();
			}
			else
			{
				XF.HCaptcha.Callbacks.push(XF.proxy(this, 'create'));

				var options = {
					dataType: 'script',
					cache: true,
					global: false
				};

				if (XF.browser.msie)
				{
					// if msie then handle calling callbacks manually due to
					// an apparent issue with onload firing on IE11
					options.url = 'https://hcaptcha.com/1/api.js?render=explicit&hl=<languagecode>';
					options.success = window.XFHCaptchaCallback;
				}
				else
				{
					options.url = 'https://hcaptcha.com/1/api.js?onload=XFHCaptchaCallback&render=explicit&hl=<languagecode>';
				}

				$.ajax(options);
			}
		},
    });
</xf:js>

But the problem is that this does not work for overlay for registration, contact and similar forms.
 
Last edited:

Similar threads

Top Bottom