• Resolved Korveld

    (@teidar)


    I need help with changing language of recaptcha for a one specific page

    The only way i found to manualy change the language of “I’m not a robot” text is to change the core code of the plugin in the file \wp-content\plugins\wpcf7-recaptcha\recaptcha-v2.php

    For example from
    'hl' => esc_attr( get_locale() );
    to
    'hl' => 'uk_UA';

    Maybe there are some hook or something like that to do it more elegant?

    • This topic was modified 3 years ago by Korveld.
    • This topic was modified 3 years ago by Korveld.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author IQComputing

    (@iqcomputing)

    Hello,

    The locale is based on the WordPress Installed site language set in Settings. There is a filter for that locale in get_locale() function.

    One possible way to work around this is to use the wp_enqueu_scripts hook to add a filter and remove the filter. It could look like this:

    /**
     * Change the locale for just one form instead of the whole website
     * Note that the action priority is important as this is what the
     * plugin uses to enqueue scripts.
     *
     * @return void
     */
    function custom_locale() {
    	add_filter( 'locale', 'update_locale' );
    }
    add_action( 'wp_enqueue_scripts', 'custom_locale', 50 );
    
    /**
     * Change the locale for just one form instead of the whole website
     * Note that the action priority is important as this runs after the
     * plugin enqueue scripts.
     *
     * @return void
     */
    function remove_custom_locale() {
    	remove_filter( 'locale', 'update_locale' );
    }
    add_action( 'wp_enqueue_scripts', 'remove_custom_locale', 51 );
    
    /**
     * Change the locale
     *
     * @param String $locale
     *
     * @return Sting $locale
     */
    function update_locale( $locale ) {
    
    	return 'uk_UA';
    
    }

    I’m not convinced yet that there is a good use-case for a filter hook in the “ReCaptcha v2 for Contact Form 7”. The forms inherit the same language that the website is set to. Since the reCaptcha script is only enqueued once, all forms would have to have the same locale. I personally believe that the best solution for this is to set the Site Language to the one you desire.

    Hopefully, the above answers your question, but should you need anything else, please reply to this thread and we can assist you further. Have a wonderful rest of your week!

    Thread Starter Korveld

    (@teidar)

    Thanks for response! Unfortunately this code doesn’t work in my case

    Thread Starter Korveld

    (@teidar)

    I’ve managed to change locale this way

    add_filter('locale', 'custom_locale', 99999);
    function custom_locale($locale) {
      if ( is_page('page_slug') ) {
        $locale = 'uk_UA';
      }
      return $locale;
    }
    Plugin Author IQComputing

    (@iqcomputing)

    @teidar We’re glad you were able to find a solution!

    In our example, the reason we add and remove this locale filter during the wp_enqueue_scripts action is to ensure that the locale only applies during the enqueue process. Otherwise, applying the filter on a global scale will change the locale for the entire page, which may have unforeseen consequences.

    Now that we see how you are implementing this, a filter may make sense. We will add a new filter for this locale on Monday to make this process easier in the future. Have a wonderful rest of your week!

    Thread Starter Korveld

    (@teidar)

    Thanks!

    Plugin Author IQComputing

    (@iqcomputing)

    Hello @teidar

    We’ve just published update 1.3.8, which includes a new filter for the Google ReCaptcha javascript Locale. The filter is: wpcf7_recaptcha_locale and can be used to change the scripts locale. You should be able to use this filter the same way as above without having the locale apply to the entire page:

    function custom_locale( $locale ) {
    	
    	if ( is_page('page_slug') ) {
    		$locale = 'uk_UA';
    	}
    
    	return $locale;
    
    }
    add_filter( 'wpcf7_recaptcha_locale', 'custom_locale' );

    Let us know if you have any questions or concerns, and have a wonderful rest of your week!

    Thread Starter Korveld

    (@teidar)

    Thanks a lot! I’ll try it)

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Manually change the language of “I’m not a robot” text’ is closed to new replies.