• Resolved aldebaran57

    (@aldebaran57)


    Hi Support

    I have a couple of multilingual sites where, after the page has downloaded, the user can select another language with a language switcher pull down menu on the page. The page content then changes to the selected language. But the Recaptcha v2 widget does not change, ie remains with showing “I am not a Robot”

    I have noticed that the widget does accept the browser configured preferred language, and so on initial page download it is in that language. So this is OK for a single language site in any language.

    But for a multilingual site you need to be able to change the language of the page after initial download, so that person can view the site in a lang other than the browser preferred one, by the user choosing the language with an on page language switcher. For example I am using the multi-lang plugin WPML which has this. But the lang of the recaptcha v2 widget does not change

    I notice that on the Google developer page for the recaptcha v2 ( https://developers.google.com/recaptcha/docs/display#config) you can force the language with url param ‘hl’ set to the desired language code.

    And it looks like setting this to the value returned from the WP core function get_locale() seems to do the trick in all cases –
    a) Just single lang website, default en_US
    b) A single website in any lang – The admin can set the lang in the
    WP backend > Settings > General
    c) A multilang website – the locale gets updated after the user chooses
    another lang with the in-page lang switcher – at least with plugin WPML,
    but I have not tried other multilang plugins, eg Polylang etc

    So I was wondering if this lang code param could be added in on a next version ? – It does not require any extra external config from the user ..

    And you already have made the error message ‘Please verify that you are not a robot’ translation ready with gettext fn call esc_html__( ‘Please verify that you are not a robot.’, ‘wpcf7-recaptcha’ )

    Meanwhile I have implemented this myself, by removing your action which adds in the google code, and defining and adding a custom action in my theme’s functions.php file, where this is exactly the same action function (copied from the original), but with the language param added in :

    CODE START :

    
    remove_action( 'wpcf7_enqueue_scripts', 'iqfix_wpcf7_recaptcha_enqueue_scripts' );
    
    add_action( 'wpcf7_enqueue_scripts', 'iqfix_wpcf7_recaptcha_enqueue_scripts_custom' );
       
    function iqfix_wpcf7_recaptcha_enqueue_scripts_custom() {
          $hl = get_locale();     // NEW
          
          $url = 'https://www.google.com/recaptcha/api.js';
          $url = add_query_arg( 
             array( 'hl' => $hl,                          // NEW 
                    'onload' => 'recaptchaCallback',
                    'render' => 'explicit',
             ), $url );
    
          wp_register_script( 'google-recaptcha', $url, array(), '2.0', true );
          wp_localize_script( 'google-recaptcha', 'wpcf7iqfix', array(
               'recaptcha_empty' => esc_html__( 'Please verify that you are not a robot.', 'wpcf7-recaptcha' ),
           ) );
    
       }
    

    Seems to work for me .. Any views ?

    Regards aldebaran57

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author IQComputing

    (@iqcomputing)

    Hello,

    Thank you for putting in the time and research into this issue! We agree that it looks like a fairly harmless and straight-forward change. We’ll pass this onto the development team and see if / when they can implement it with a future version of the plugin. We will keep this thread open so we can keep you updated on the development of this feature. Have a wonderful rest of your week!

    Thread Starter aldebaran57

    (@aldebaran57)

    Ok thanks

    I forgot to emphasise that any translation ready gettext function calls work fine (ie appear in the correct lang) in my cases a) ,b), c) above. And this includes your error message ‘Please verify that you are not a robot’ for the Recaptcha V2 plugin. It’s just that the the Google widget itself does not, because the widget and so the ‘I am not a Robot’ text etc is not part of this gettext API. So it looks like you need to tell it explicitly to react to the latest locale.

    Note, I am not sure what the difference is between whats in $locale and what is returned from get_locale(), but the function seems to cover all bases if you look in its source code

    Regards aldebaran57

    Plugin Author IQComputing

    (@iqcomputing)

    Hello,

    Thank you again for your suggestion! It’s people like you and suggestions like this that help make this plugin more accessible and better with every update. We’ve added your suggestion to the latest update v1.1.6 which can be downloaded from the main plugin page. We’ll mark this topic resolved for now, have a wonderful rest of your week!

    Thread Starter aldebaran57

    (@aldebaran57)

    Hi @iqcomputing

    OK great ! – I will download the new version

    Regards Regards aldebaran57

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Force language of Widget so it reacts to Language Switcher on Multi-lang sites’ is closed to new replies.