Viewing 11 replies - 1 through 11 (of 11 total)
  • This is a nice “how to” article for Contact Form 7 plugin.
    http://dejanjanosevic.info/change-language-recaptcha-contact-form-7/

    You just need to change the action and language. I would try wp_loaded: https://codex.ww.wp.xz.cn/Plugin_API/Action_Reference/wp_loaded

    Thread Starter Webzzz

    (@webzzz)

    Thank you for your answer Igor, isn’t this solution will make it always same language? what if you have few languages? [we use wpml, and we have 3 languages]

    Thread Starter Webzzz

    (@webzzz)

    and is this plugin using contact-form-7?

    Thread Starter Webzzz

    (@webzzz)

    Do you think this will work?

    
    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 );
    		}
    	}
    
    Thread Starter Webzzz

    (@webzzz)

    πŸ™ it doesn’t work

    and I have try the below code too, it’s also not working:

    
    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' => 'fr-CA' ), $url );
    
    	wp_register_script( 'google-recaptcha', $url, array(), '2.0', true );
    }
    
    • This reply was modified 7 years, 10 months ago by Webzzz.
    Plugin Author Fernando Claussen

    (@fclaussen)

    I wasn’t aware we could translate those. I’ll get the code updated to figure out the current language code and hopefully load the correct recaptcha language.

    Thread Starter Webzzz

    (@webzzz)

    looking forward for the code/solution, can you please let me know?

    thank you Fernando for the awesome plugin!

    Thread Starter Webzzz

    (@webzzz)

    How about similar code to this:

    
    public function init() {
            $attr = $this->getAttr();
     
            //Site Key
            $this->pubkey = isset( $attr['public_key'] ) ? $attr['public_key'] : '';
            //Secret Key
            $this->privkey = isset( $attr['private_key'] ) ? $attr['private_key'] : '';
     
            // get_user_locale() was introduced in WordPress 4.7
            $locale = ( function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale() );
            $user_locale_lang = substr( $locale, 0, 2 );
     
            $wpml_source_lang = isset( $_REQUEST['source_lang'] ) ? sanitize_text_field( $_REQUEST['source_lang'] ) : apply_filters( 'wpml_current_language', null );
            $wpml_lang = isset( $_REQUEST['lang'] ) ? sanitize_text_field( $_REQUEST['lang'] ) : $wpml_source_lang;
     
            $lang = isset( $wpml_lang ) ? $wpml_lang : $user_locale_lang;
     
            wp_enqueue_script( 'wpt-cred-recaptcha', '//www.google.com/recaptcha/api.js?onload=onLoadRecaptcha&render=explicit&hl=' . $lang );
        }
    
    Thread Starter Webzzz

    (@webzzz)

    or like this solution…

    https://wpml.org/forums/topic/how-to-translate-recaptcha-in-contact-form-7/

    docs by Google

    https://developers.google.com/recaptcha/docs/language

    or this:

    https://github.com/mcguffin/wp-recaptcha-integration/wiki/The-Language-Setting

    Line 185:
    https://github.com/kasparsd/contact-form-7-extras/blob/master/plugin.php

    • This reply was modified 7 years, 10 months ago by Webzzz.
    • This reply was modified 7 years, 10 months ago by Webzzz.
    • This reply was modified 7 years, 10 months ago by Webzzz.

    Sorry for the late reply Webzzz. Honestly, I would wait for Fernando to implement this functionality into plugin.

    I really like the solution you mentioned https://wpml.org/forums/topic/how-to-translate-recaptcha-in-contact-form-7/ but I haven’t tested it. I always use Polylang for multilingual pages. However, not even Polylang supports the translation of Google reCaptcha. Honestly, I think that reCaptcha is quite outdated, e.g. it’s very hard to make it responsive.

    Plugin Author Fernando Claussen

    (@fclaussen)

    I just got back from vacation. This is on my list of things to do for the next release.

    I’m just catching up to everything that happened in the last couple weeks.

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘reCAPTCHA multilingual capabilities’ is closed to new replies.