I realize that it is trivial to change the Recaptcha language by adding the "hl" option to api.js.
https://www.google.com/recaptcha/api.js?hl=fr
What I would like to do is change the Recaptcha language when someone clicks on a language picker which is exposed via a QueryString parameter such as "?lang=fr" I have js that will parse the parameter but I cannot seem to reload the script in the head tag to include the param.
I've looked at all the conditional IF...ELSE javascript loading articles. Is there any way to load Recaptcha options with version 2?
Simple solution
You can do it like this:
HTML
JS
Online demo (jsFiddle)
I do not think it is possible to do set recaptcha language through javascript directly at the moment. As you stated, it is however possible using the parameter 'hl' during script loading.
If you need to change the language of your application dynamically without reloading the page, you can do this by removing the recaptcha script link from the head section and instead, loading it directly with a call from javascript. When your user changes the language by clicking a button, you can now reload recaptcha with the new language by calling the load function again.
In my case the recaptcha element is shown inside a modal, the user response is sent to the server over ajax and is validated on the server side against Google. Something like this does the trick:
Now, at page load or when the user selects a new language, you can do:
And it should remove the existing recaptcha object from the page and reload one in the correct language. After that you can open the modal using: