Plugin Author
MihChe
(@mihche)
Hi @raykaii,
The Language Detection is automatically handled by Google (based on browser settings) and there is nothing I can do.
I was also reading several forums posts and it seems to be a common issue.
In this case, all I can do is to provide a hook to programmatically change the language code.
Please let me know if you or anybody else is interested in this solution and I’ll implement it.
~Mihai
i would love it if it would work. dont know how hook work tho… but i need it to switch language when ppl are in an other language other then English.
thx for your time.
Plugin Author
MihChe
(@mihche)
I will add the hook and I’ll post some examples of how to use it.
~Mihai
Plugin Author
MihChe
(@mihche)
Hi
Let’s try this to change the language code based on WPML
add_filter('google_invre_language_code', function ($languageCode){
return defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : $languageCode;
});
Please let me know
~Mihai
ok i can try it where should i add the code ?
Plugin Author
MihChe
(@mihche)
In your child theme you should have the functions.php file.
If you do not have a child theme, you can add it directly to theme functions.php file.
Let me know,
Mihai
Hello
Just had the same problem and added the filter (though it’s google_invre_language_code_filter and not google_invre_language_code).
You could add another option to the dropdown language that could be “Use wordpress language” and where we wouldn’t need to add the filter function to obtain the same results.
Thanks for the work!
as says the post above the correct code is:
// Invisible reCaptcha change language based on WPML
add_filter('google_invre_language_code_filter', function ($languageCode){
return defined('ICL_LANGUAGE_CODE') ? ICL_LANGUAGE_CODE : $languageCode;
});
would be nice to have this code in the plugin as an extra option in the drop-down language that could be “Use WPML language”
Thanks for the plugin, but would be nice if we could avoid it.
For example, here’s code that does not depend on the plugin (WPML), just uses WordPress functions:
/**
* Google recaptcha has a bug, does not automatically handle language and ignores
* WordPress header which looks like this: <html lang="fr-CA" ...>
* So have to add hl=<lang code> to the API call:
* https://www.google.com/recaptcha/api.js?hl=<language code>
* Use the Invisible Recaptcha plugin hook to insert that, based on standard
* WordPress functions.
*/
add_filter('google_invre_language_code_filter', function ($languageCode){
$languageCode = get_bloginfo( 'language' ); // 'en-US', 'fr-CA', etc
return $languageCode;
});
[Moderator note: code fixed. Please wrap code in the backtick character or use the code button.]
-
This reply was modified 7 years, 4 months ago by
bdbrown.