Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1374218

    Hello!

    I’m using ENFOLD with WPML, all it works fine in 3 languages.
    Although I’m looking for translate Google Recaptcha v2 box : “I’m not a robot” and Terms / Privacity links
    in different languages, now appears in es-ES for all languages.

    I have not found a way to configure it to show the Recaptcha box depending on the language of the page.

    Can you tell me how to solve it?

    Thanks in advance!

    #1374230

    Hey abeldb,

    Thank you for the inquiry.

    The widget will automatically switch to the language of the user or visitor who is viewing the site. Since you are probably in a country using the ES language and your browser set to use the ES language, the widget also uses the ES language. For EN users, the widget will display in EN, same for other languages.

    But if you want the widget to automatically switch based on the site’s current language, please edit the enfold\framework\php\class-grecaptcha.php, replace everything with the code below.

    // https://pastebin.com/hMZWNUMJ

    Then add this filter in the functions.php file.

    add_filter('av_google_recaptcha_apiurl', function($url) {
    				$lang = apply_filters( 'wpml_element_language_code', null);
    				$url = $url . "?hl=" . $lang;
    				return $url;
    			}, 10, 1);
    

    Best regards,
    Ismael

    #1374254

    Hi Ismael!
    thanks for your quick response.

    Yes, it is better for Recaptcha to change the language according to the language of the page (not the language of the user in his browser/system).

    __
    I have created a copy of the file “class-grecaptcha.php”, as you indicate.
    And I have added the filter in functions.php of the child theme, but when adding the filter, it generates an Error

    Uncaught ArgumentCountError: Too few arguments to function wpml_element_language_code_filter(), 1 passed in wp-includes/class-wp-hook.php on line 308 and exactly 2 expected in wp-content/plugins/sitepress-multilingual-cms/inc/template-functions.php:1310
    Stack trace:
    #0 wp-includes/class-wp-hook.php(308): wpml_element_language_code_filter(NULL)
    #1 wp-includes/plugin.php(205): WP_Hook->apply_filters(NULL, Array)
    #2 wp-content/themes/enfold-child/functions.php(1414): apply_filters('wpml_element_la...', NULL)
    #3 wp-includes/class-wp-hook.php(308): {closure}('https://www.goo...')
    #4 wp-includes/plugin.php(205): WP_Hook->apply_filters('https://www.goo...', Array)
    #5 wp-content/themes/enfold/framework/php/class-grecaptcha.php(286): apply_filters('av_google_recap...', 'https://www.goo...')

    Can you tell me how to fix it?

    __
    In other side, It would be preferable that the “class-grecaptcha.php” file be replaced in the child theme (or maybe dequeued and queued via child functions), to avoid it being deleted in future updates of the parent theme Enfold.

    Ismael thanks again for your help

    Best regards!

    #1374458

    Hi,

    Our devs have added a filter “avf_google_recaptcha_apiurl” which will be available in Enfold 5.3

    Could you please try changing the code to following one

    
    add_filter('av_google_recaptcha_apiurl', function($url) {
    				$lang = apply_filters( 'wpml_element_language_code', null, $args);
    				$url = $url . "?hl=" . $lang;
    				return $url;
    			}, 10, 1);
    

    Best regards,
    Yigit

    #1374477

    Hello Yigit!
    Adding the ability to set the Recaptcha language in the next update is a great idea.
    I think it’s fantastic idea.

    __
    Regarding the updated code, thanks for the agility.
    But now the Recaptcha box is hidden, although it is working, it is not showing on frontend (in any language).

    Thanks again in advance

    Best regards

    #1374563

    Hi!

    Thanks for following up.

    Please replace the enfold\framework\php\class-grecaptcha.php again with the updated code below.

    // https://pastebin.com/aT4tDH0c

    Then use this filter instead.

    add_filter('avf_google_recaptcha_apiurl', function($apiurl, $context) {
    	if($context == 'frontend')
    	{
    		$lang = apply_filters( 'wpml_element_language_code', null, []);
    		$apiurl = $apiurl . "?hl=" . $lang;
    	}
    
    	return $apiurl;
    }, 10, 2);
    

    If the issue persists, please provide the WP and FTP details in the private field so that we can test the changes.

    Regards,
    Ismael

    #1374683
    This reply has been marked as private.
    #1374726

    Hi,

    Thank you for the info.

    We also modified the avia_google_recaptcha_api.min.js file, and adjusted the filter. (see private field)

    // https://kriesi.at/support/topic/recaptcha-v2-wpml/#post-1374230
    add_filter('avf_google_recaptcha_apiurl_lang', function($lang, $context) {
    	if($context == 'frontend')
    	{
    		$lang = substr(get_locale(), 0, 2);
    	}
    
    	return $lang;
    }, 10, 2);
    

    Result: https://imgur.com/a/tWiDSL4

    Best regards,
    Ismael

    #1374758

    YABADADOOOOOO!!!
    it’s fantastic!!
    Thank you very much for your efforts.

    —–
    From what you said, I understand that the files you have updated from the parent theme will be included in the next Enfold update.
    It is right? (I’ll keep an eye out in case something new needs to be configured in the theme settings.)

    if not, can you tell me how to proceed so that this setting is not lost in the next ENFOLD update?

    Thank you very much!
    Best Regards!

    #1375077

    Hi,

    No problem. We will probably include the changes in the next patch. If not, you can create a backup of the files that we edited above and re-apply them in the next update.

    Thank you for your patience.

    Best regards,
    Ismael

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.