RecaptchaOptions not working to set language

7,779 views
Skip to first unread message

dirtside

unread,
Jan 31, 2012, 2:01:55 PM1/31/12
to reCAPTCHA
My code is down below. It's a bare-bones PHP script, using the PHP
reCAPTCHA library provided by Google (recaptchalib.php). The captcha
mechanism itself works fine, but I cannot get it to show the reCAPTCHA
form in any language besides English. According to Google's docs, you
just put in a script tag with a RecaptchaOptions variable in it, as
I've done below. Yet no matter what I do, it shows the form in English
only. "Type the two words:", "stop spam. read books", etc. What am I
doing wrong here?

The behavior is the same in FF 8 and Chrome 16 on Linux, and FF 9 on
Windows.

<?php
$publickey = '[hidden]';
$privatekey = '[hidden]';

require_once('recaptchalib.php');
?>

<script type="text/javascript">
var RecaptchaOptions = {
"lang": "es",
};
</script>

<form method="post">
<?
echo recaptcha_get_html($publickey);
?>
<br>
<input type="submit" value="submit">
</form>

dirtside

unread,
Jan 31, 2012, 2:05:48 PM1/31/12
to reCAPTCHA
Just a note, I looked around and found another site that uses
reCAPTCHA, and also attempts to use RecaptchaOptions to change the
language, and it doesn't work there, either. I don't know if that
site's author is aware of that or not, but it's http://sheetmusicdb.net/kontakt.php?lg=de

Notice that the reCAPTCHA form is in English even though the JS to set
the RecaptchaOptions is present in the page's HTML and tries to set
the language to 'de'.

PJH

unread,
Jan 31, 2012, 2:13:42 PM1/31/12
to reca...@googlegroups.com
On Tue, Jan 31, 2012 at 7:01 PM, dirtside <dirt...@gmail.com> wrote:
> var RecaptchaOptions = {
>    "lang": "es",
> };

Spanish isn't on the current list of supported languages.

http://code.google.com/apis/recaptcha/docs/customization.html#i18n


--
PJH

dirtside

unread,
Jan 31, 2012, 2:20:12 PM1/31/12
to reCAPTCHA
On Jan 31, 11:13 am, PJH <pauljherr...@gmail.com> wrote:
> On Tue, Jan 31, 2012 at 7:01 PM, dirtside <dirts...@gmail.com> wrote:
> > var RecaptchaOptions = {
> >    "lang": "es",
> > };
>
> Spanish isn't on the current list of supported languages.
>
> http://code.google.com/apis/recaptcha/docs/customization.html#i18n

Er, I'm not sure what you mean; Spanish is listed in the table on the
right side that lists what languages are supported (in the
"RecaptchaOptions Reference" table). So are French, Dutch, German, and
Portuguese. I've tried all those lang codes and none of them cause the
form to change what language it's in.

dirtside

unread,
Jan 31, 2012, 2:21:34 PM1/31/12
to reCAPTCHA
Incidentally, I just tried putting in the 'theme' key into the
Javascript array, and it correctly caused the theme of the reCAPTCHA
form to change (I put in theme: 'white' and the form appeared as white
on the next page load). But it's ignoring 'lang'.

PJH

unread,
Jan 31, 2012, 2:52:05 PM1/31/12
to reca...@googlegroups.com
On Tue, Jan 31, 2012 at 7:20 PM, dirtside <dirt...@gmail.com> wrote:
> Er, I'm not sure what you mean; Spanish is listed in the table on the
> right side that lists what languages are supported

Oops - didn't read it closely enough - sorry!


--
PJH

PJH

unread,
Jan 31, 2012, 2:54:28 PM1/31/12
to reca...@googlegroups.com
On Tue, Jan 31, 2012 at 7:01 PM, dirtside <dirt...@gmail.com> wrote:
> <script type="text/javascript">
> var RecaptchaOptions = {
>    "lang": "es",
> };
> </script>

Just a thought - could that trailing comma after "es" be anything to
do with it? e.g.
<http://www.enterprisedojo.com/2010/12/19/beware-the-trailing-comma-of-death/>

--
PJH

dirtside

unread,
Jan 31, 2012, 3:16:43 PM1/31/12
to reCAPTCHA
On Jan 31, 11:54 am, PJH <pauljherr...@gmail.com> wrote:
> On Tue, Jan 31, 2012 at 7:01 PM, dirtside <dirts...@gmail.com> wrote:
> > <script type="text/javascript">
> > var RecaptchaOptions = {
> >    "lang": "es",
> > };
> > </script>
>
> Just a thought - could that trailing comma after "es" be anything to
> do with it? e.g.
> <http://www.enterprisedojo.com/2010/12/19/beware-the-trailing-comma-of...>

Yeah, I had messed around with that too. No dice; makes no difference.
I've also tried every conceivable variation on quote marks, just in
case:

lang: 'es',
lang: "es",
'lang': 'es',
'lang': "es",
"lang": 'es',
"lang": "es",

None of them matter. I've also tried having the 'lang' and 'theme'
properties in different orders, put other gibberish properties there,
etc.

I did try to debug the recaptcha JS a little; on line 117 of the
recaptcha.js file is a function called Recaptcha.getLang_(). This
function looks at the RecaptchaState object and then the
RecaptchaOptions object in order to figure out what language to use. I
can't figure out why, but for some reason RecaptchaState.lang already
has a value ('en') so it never even looks at RecaptchaOptions, I think
is what happening, but I'm not sure why this would be.

Gloria2

unread,
Feb 1, 2012, 3:22:43 AM2/1/12
to reCAPTCHA
Hi,
I’m also struggling with the language bit. I have noticed that the
explaining text on the image changes depending on from what country
the reCaptcha is called, i.e. when called from a Cypriot IP address
the text displays in Greek, and when called from a UK IP address the
text displays in English. That is very smart and nice, but I want the
text to always display in English irrespective of what country you’re
calling the reCaptcha from.
Dirtside, you sound like you know your way around code, so can you, or
anybody else, please tell me if there is anywhere in the following
code that I can insert the language switch?




/**
 * Gets the challenge HTML (javascript and non-javascript version).
 * This is called from the browser, and the resulting reCAPTCHA HTML
widget
 * is embedded within the HTML form it was called from.
 * @param string $pubkey A public key for reCAPTCHA
 * @param string $error The error given by reCAPTCHA (optional,
default is null)
 * @param boolean $use_ssl Should the request be made over ssl?
(optional, default is false)




 * @return string - The HTML to be embedded in the user's form.
 */
function recaptcha_get_html ($pubkey, $error = null, $use_ssl = false)
{
if ($pubkey == null || $pubkey == '') {
return
'<div>'.JText::_('COM_PHOCAGUESTBOOK_RECAPTCHA_ERROR_GET_API').
'<br /> <a href=\'https://www.google.com/recaptcha/admin/create
\'>https://www.google.com/recaptcha/admin/create</a></div>';
}

if ($use_ssl) {
                $server = RECAPTCHA_API_SECURE_SERVER;
        } else {
                $server = RECAPTCHA_API_SERVER;
        }




        $errorpart = "";
        if ($error) {
           $errorpart = "&amp;error=" . $error;
        }
        return '<script type="text/javascript" src="'. $server . '/
challenge?k=' . $pubkey . $errorpart . '"></script>




<noscript>
  <iframe src="'. $server . '/noscript?k=' . $pubkey . $errorpart .
'" height="300" width="500" frameborder="0"></iframe><br/>
  <textarea name="recaptcha_challenge_field" rows="3" cols="40"></
textarea>
  <input type="hidden" name="recaptcha_response_field"
value="manual_challenge"/>
</noscript>';
}




I’m using the reCaptcha with PhocaGuestbook on Joomla.




Hopefull regards / Gloria

dirtside

unread,
Feb 1, 2012, 7:25:41 PM2/1/12
to reCAPTCHA
I don't know if there IS anything you can do. I'm considering hosting
the recaptcha.js file locally and editing it to fix the bug.
Alternatively, we might just provide our own translated text, which
DOES work.
>            $errorpart = "&error=" . $error;

Bob

unread,
Feb 9, 2012, 12:44:57 PM2/9/12
to reca...@googlegroups.com
This must be a new bug.  I know it has worked in the past.  Hopefully Google fixes it quickly!

In the mean time another workaround in case this is useful to anyone: create the challenge div from javascript upon page load using Google's Recaptcha.create() function (defined in http://www.google.com/recaptcha/api/js/recaptcha_ajax.js):
<html>
<head>
<script type="text/javascript" src="http://www.google.com/recaptcha/api/js/recaptcha_ajax.js"></script> 
</head>
<body>
<form>
<div id="myrecapdiv1" style="display:none;" />
<script type="text/javascript">
        Recaptcha.create(
            "your_public_key"
            , "myrecapdiv1"
            , { lang: "es" }
            );
</script>
</form>
</body>
</head>

Bob

unread,
Feb 9, 2012, 2:09:59 PM2/9/12
to reca...@googlegroups.com
Good news everyone!

I have some more info that will help you.  A clue left by one of the posters in https://groups.google.com/d/topic/recaptcha/cFvBBhUonOA/discussion led me to discover that if you really want to override the language (which it sounds like maybe there's no need to do anymore, because it's defaulting to the browser's language now), you can do so by appending a value with key "hl" to your challenge script query string.  So where you currently have:
   <script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=your_public_key" />
if you want to force, say, French, you could do:

(only difference is the "&hl=fr" at the end there)

dirtside

unread,
Feb 28, 2012, 2:49:45 PM2/28/12
to reCAPTCHA
It works! Yay! Thanks!

On Feb 9, 11:09 am, Bob <bob.cardi...@gmail.com> wrote:
> Good news everyone!
>
> I have some more info that will help you.  A clue left by one of the
> posters inhttps://groups.google.com/d/topic/recaptcha/cFvBBhUonOA/discussionled me

Pedro Manaças

unread,
May 16, 2012, 10:44:53 PM5/16/12
to reca...@googlegroups.com
Just to add to this (this thread ranks quite high on Google when you search for this problem, so it may be useful to others in the future)

If you already localize your site via a serverside framework
you can simply pass the locale code to the query string in the js call

it accepts a lot more languages than the ones mentioned in the docs (i guess the docs must be outdated)

things like
hl='pt_PT'
hl='pt_BR'

etc

they all work (and even have specific localizations for those variants)

Bipul Kuri

unread,
Jul 1, 2013, 11:08:37 AM7/1/13
to reca...@googlegroups.com
Done some code change have a look to support multiple languages
http://bipulkkuri.wordpress.com/2013/07/01/recaptcha-language-support/
Reply all
Reply to author
Forward
0 new messages