Skip Navigation

[Resolved] Recaptcha Language Setting

This thread is resolved. Here is a description of the problem and solution.

Problem:
Translate Strings in CRED ReCaptcha into multiple language

Solution:
You need to dequeue and enqueue the CRED ReCaptcha script with your desired language code.

You can find the proposed possible solution in this case with the following reply:
https://toolset.com/forums/topic/recaptcha-language-setting/#post-618961

Relevant Documentation:

This support ticket is created 6 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 9 replies, has 2 voices.

Last updated by anastasiosD 6 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#618773

On one of my contact forms I need to set the Google captcha language "I'm not a robot" to Greek 'el'
The partial form code is as follows:

<div class="form-group">[cred_field field='recaptcha' value='' urlparam='' class='form-control' output='bootstrap']</div>
[cred_field field='form_submit' value='Submit' urlparam='' class='btn btn-primary btn-lg' output='bootstrap']
[/credform]

Where exactly do I specify the language parameter?

Thank you

#618873

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Please allow me to consult our Devs on this issue and I'll get in touch with you as soon as possible.

#618961

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I got the update and you can try to change the language for your captcha by:
- Dequeue the wpt-cred-recaptcha script
- Enqueue the script again with your required language

For example:

wp_enqueue_script( 'wpt-cred-recaptcha', '//www.google.com/recaptcha/api.js?onload=onLoadRecaptcha&render=explicit&hl=el');
#619001

Thank you for your reply,
But I'm afraid this solution is not acceptable because it will force only one language by using the explicit setting, which in turn means when a client switches to English he will still see the Greek version, because this change is implemented via the functions.php file.

How can I pass a the language parameter via the form itself, so I can at least build two different forms?

If you can be as specific as possible it would be appreciated.

Also is it possible that you are forcing the hl=en parameter in your script? Normally if a user's browser language setting is in a different language other than English, recaptcha should automatically follow the user's browser language setting, which is not the case here. Can you also look into this?

Thank you

#619590

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - I would like to know - are you using WPML plugin here?

What is the param based on that we can know the current language you are loading?

#619627

Hi,
Thank you for your reply.
Let's try not to over complicate this simple issue.

Please read Google's reCAPTCHA implementation for developers here:
hidden link
and also see the all the available language codes here:
hidden link

The WPML plugin that you are referring to has absolutely nothing to do with this issue, and no I am not using that plugin.

The fact is that your plugin developer has omitted the implementation for setting the lang parameter, making it difficult for multilingual website owners to use the reCAPTCHA feature in it's localized version.

So I would appreciate it very much if you can speak to the software developer and ask him to implement a localization (lang parameter) setting in the next update to solve this issue.

Why make things so difficult, when all I need is to append a parameter like so:
<script src='hidden link;

Thank you

#619647

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - if you will check the following file:

plugins\cred-frontend-editor\vendor\toolset\toolset-common\toolset-forms\classes\class.recaptcha.php

You will see the following function - Where we are retrieving user local language using function get_user_locale() but not the browser's default language. So, this is how the language for ReCaptcha is loaded using following code:

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 );
	}

I will check with Dev and share your comments with him and will get in touch with you as soon as possible.

#619660

Good morning Minesh,

Thank you for your prompt reply.
I will be expecting a reply, hopefully together with a solution that allows me to set the language to my liking on each form I create.
Even though Google's reCaptcha has language auto-detect and so if it's not explicitly set it will default to the language set by the user's browser, the feature does not work properly all the time so it's not reliable. This if course is a Google issue.

But the best way to implement and correct the problem is to allow the user to append the ?hl=xx to the URL to every instance of the form that the user has created and this may only be done via your plugin.

Have a great day

#619687

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - as you can see with the code - there is no such option to set the language param manually, I will ask our Dev and pass your concern as feature request for assessment and it will take considerable time as it's totally depend on predefined priorities set for our Devs.

The only way for now is to customize it by adding some custom code to your current theme's functions.php file. As described by me with following reply:
=> https://toolset.com/forums/topic/recaptcha-language-setting/#post-618961

#619695

Hey Minesh,

I really appreciate the fact that you tried to help.

I understand about the existing priorities, but please make sure this issue gets on the list of things to do with your devs, this way we will not have to address the same issue 10 months from now, because in reality it is a very simple fix.

Thanks again