Skip to content

Instantly share code, notes, and snippets.

@athlonUA
Last active April 29, 2019 08:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save athlonUA/ed5b19ec905d354609d4f58fe863db9a to your computer and use it in GitHub Desktop.
Save athlonUA/ed5b19ec905d354609d4f58fe863db9a to your computer and use it in GitHub Desktop.
Google reCAPTCHA V2. Change language in real time
// Enum for language codes
var languageListsGoogleCaptchaEnum = {
Arabic: 'ar',
Afrikaans: 'af',
Amharic: 'am',
Armenian: 'hy',
Azerbaijani: 'az',
Basque: 'eu',
Bengali: 'bn',
Bulgarian: 'bg',
Catalan: 'ca',
Chinese_HongKong: 'zh-HK',
Chinese_Simplified: 'zh-CN',
Chinese_Traditional: 'zh-TW',
Croatian: 'hr',
Czech: 'cs',
Danish: 'da',
Dutch: 'nl',
English_UK: 'en-GB',
English_US: 'en',
Estonian: 'et',
Filipino: 'fil',
Finnish: 'fi',
French: 'fr',
French_Canadian: 'fr-CA',
Galician: 'gl',
Georgian: 'ka',
German: 'de',
German_Austria: 'de-AT',
German_Switzerland: 'de-CH',
Greek: 'el',
Gujarati: 'gu',
Hebrew: 'iw',
Hindi: 'hi',
Hungarain: 'hu',
Icelandic: 'is',
Indonesian: 'id',
Italian: 'it',
Japanese: 'ja',
Kannada: 'kn',
Korean: 'ko',
Laothian: 'lo',
Latvian: 'lv',
Lithuanian: 'lt',
Malay: 'ms',
Malayalam: 'ml',
Marathi: 'mr',
Mongolian: 'mn',
Norwegian: 'no',
Persian: 'fa',
Polish: 'pl',
Portuguese: 'pt',
Portuguese_Brazil: 'pt-BR',
Portuguese_Portugal: 'pt-PT',
Romanian: 'ro',
Russian: 'ru',
Serbian: 'sr',
Sinhalese: 'si',
Slovak: 'sk',
Slovenian: 'sl',
Spanish: 'es',
Spanish_LatinAmerica: 'es-419',
Swahili: 'sw',
Swedish: 'sv',
Tamil: 'ta',
Telugu: 'te',
Thai: 'th',
Turkish: 'tr',
Ukrainian: 'uk',
Urdu: 'ur',
Vietnamese: 'vi',
Zulu: 'zu',
};
// Update language captcha
function updateGoogleCaptchaLanguage(selectedLanguage) {
var iframeGoogleCaptcha = (document.getElementById('recaptcha')).getElementsByTagName('iframe')[0];
var language = iframeGoogleCaptcha.src.match(/hl=(.*?)&/).pop();
iframeGoogleCaptcha.src = iframeGoogleCaptcha.src.replace(/hl=(.*?)&/, 'hl=' + selectedLanguage + '&');
}
@athlonUA
Copy link
Author

You need simply call updateGoogleCaptchaLanguage(selectedLanguage) with selected language

@athlonUA
Copy link
Author

athlonUA commented Mar 18, 2018

recaptcha in the code above is the id of the div with initialized google recaptcha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment