How to set the reCaptcha language?
-
How can I set the language of reCaptcha if the auto-detect isn’t useful for me?
-
@krko Thx for the how-to, it is very helpful
Contactform7 recognizes the languages I have set on sites, but the recaptcha strangely enough does not, which is especially a problem on my multilingual site because there all languages in recaptcha now revert to the Dutch language. Would also appreciate an easy workaround for this
thank you,
Yolanda@krko – thanks for the instructions!
@takayuki Miyoshi – please add this small parameter to the plugin. It will make the reCaptcha integration complete for people running sites in languages other than English. Google’s auto-detect doesn’t work, and unfortunately chances are slim they’ll do anything about. It would be great if the language could be explicitly set in the integration admin, or through a hook on a child theme’s functions.php so it can be update-proof.
@nathair perhaps you can try this (it’s an expansion from the solution provided by krko)
In the same file recaptcha.php under modules folder line 240, add the checking of the language (in my case it’s either English or Japanese by default, so please change accordingly):
function wpcf7_recaptcha_enqueue_scripts() { $url = 'https://www.google.com/recaptcha/api.js'; $lang = get_bloginfo('language'); if ( $lang === 'en-US' ) { $url = add_query_arg( array( 'onload' => 'recaptchaCallback', 'hl' => 'en', 'render' => 'explicit' ), $url ); } else { $url = add_query_arg( array( 'onload' => 'recaptchaCallback', 'hl' => 'ja', 'render' => 'explicit' ), $url ); } wp_register_script( 'google-recaptcha', $url, array(), '2.0', true ); }
All the best,
EunikeYou don’t need to change the plugin’s code to specify the reCAPTCHA widget language. Instead, just add this code to your theme’s functions.php or so.
add_action( 'wpcf7_enqueue_scripts', 'custom_recaptcha_enqueue_scripts', 11 ); function custom_recaptcha_enqueue_scripts() { wp_deregister_script( 'google-recaptcha' ); $url = 'https://www.google.com/recaptcha/api.js'; $url = add_query_arg( array( 'onload' => 'recaptchaCallback', 'render' => 'explicit', 'hl' => 'ar' ), $url ); wp_register_script( 'google-recaptcha', $url, array(), '2.0', true ); }
Available language codes are listed here.
@takayuki Miyoshi – thanks for that solution. I think it would be worthwhile to add this to the documentation at https://contactform7.com/recaptcha/??.
You can now specify the Google Recaptcha language parameter in the settings provided by the Contact Form 7 Controls plugin.
@takayuki Miyoshi
Thank you very much! That was exactly what I have been looking for; relieved that I could leave the plugin’s code undisturbed.
Cheers,
Eunike@takayuki Miyoshi Thank you!
Note that you don’t need to specify the widget language because reCAPTCHA can auto-detect the user’s language if unspecified. Specifying the widget language kills auto-detect and it should be bad for usability in 99% of cases. I don’t recommend it.
Thanks @kaspars, that’s exactly what I needed too.
The language setting for Recaptcha is workingthank you all
thank you all
Thank you @kaspars. Your Contact Form 7 Controls plugin is doing the job.
@takayuki Miyoshi Thanks for creating a great plugin.
Thanks all for making a better plugin.
In case someone needs language switching on the fly, i.e. when using a multilingual plugin, here’s a slightly modified version of the function ‘custom_recaptcha_enqueue_scripts’:
function custom_recaptcha_enqueue_scripts() { $current_lang = false; // lang from a multilang plugin (if any used) if(class_exists('WPGlobus')){ // WPGlobus found $current_lang = WPGlobus::Config()->language; } else if(defined('ICL_LANGUAGE_CODE')){ //Perhaps WPML?? $current_lang = ICL_LANGUAGE_CODE; } // provided recaptcha langs from google (as of March 24th, 2016) $provided_langs = array('ar','af','am','hy','az','eu','bn','bg','ca','zh-HK','zh-CN','zh-TW','hr','cs','da','nl','en-GB','en','et','fil','fi','fr','fr-CA','gl','ka','de','de-AT','de-CH','el','gu','iw','hi','hu','is','id','it','ja','kn','ko','lo','lv','lt','ms','ml','mr','mn','no','fa','pl','pt','pt-BR','pt-PT','ro','ru','sr','si','sk','sl','es','es-419','sw','sv','ta','te','th','tr','uk','ur','vi','zu'); if(in_array($current_lang, $provided_langs)) { // remove CF7 script call wp_deregister_script( 'google-recaptcha' ); $url = 'https://www.google.com/recaptcha/api.js'; $url = add_query_arg( array( 'onload' => 'recaptchaCallback', 'render' => 'explicit', 'hl' => $current_lang ), $url ); // load recaptcha with language parameter wp_register_script( 'google-recaptcha', $url, array(), '2.0', true ); } }
So far I only used WPGlobus and WPML for my projects, but the first if clause should be easily updated ??
- The topic ‘How to set the reCaptcha language?’ is closed to new replies.