Setting reCAPTCHA Version 2 set another language other than English

后端 未结 5 486
走了就别回头了
走了就别回头了 2021-01-30 16:19

\"enter

How can I set this in another language, ie:. French

I\'ve tried:

5条回答
  •  生来不讨喜
    2021-01-30 17:00

    Thank you @ali-soltani for snipped! Did the thing! :)

    I am providing my "vanilla" version for those who do not use jQuery, to save the few strikes.

        function setCaptchaLang(lang) {
    
          const container = document.getElementById('captcha_container');
    
          // Get GoogleCaptcha iframe
          const iframeGoogleCaptcha = container.querySelector('iframe');
    
          // Get language code from iframe
          const actualLang = iframeGoogleCaptcha.getAttribute("src").match(/hl=(.*?)&/).pop();
    
          // For setting new language
          if (actualLang !== lang) {
            iframeGoogleCaptcha.setAttribute("src", iframeGoogleCaptcha.getAttribute("src").replace(/hl=(.*?)&/, 'hl=' + lang + '&'));
          }
        }
    

提交回复
热议问题