Can I use ReCaptcha in another language?

ReCaptcha is the widely used anti-spam tool from Google; you can use it in ChronoForms with the Load ReCaptcha and Check ReCaptcha actions. By default ReCaptcha only supports a small number of languages. But with a simple code hack you can add another one. Here's how I built a Welsh version.

This FAQ requires you to hack the core ChronoForms files. It is not recommended unless you are familiar with PHP and JavaScript. You will need to repeat the hack when you upgrade ChronoForms to a future release. You have been warned!

 You will need to edit this file: 
/administrator/components/com_chronoforms/form_actions/load_recaptcha/load_recaptcha.php
Look for the following code around line 28:
$script = "
var RecaptchaOptions = {
  theme : '".$params->get('theme', 'red')."',
  lang  : '".$params->get('lang', 'en')."'
};
";
I replaced this block with this code:
$lang =& JFactory::getLanguage();
$tag = $lang->getTag();
if ( $tag == 'cy-GB' ) {
  $script = "
var RecaptchaOptions = {
  theme : '".$params->get('theme', 'red')."',
  custom_translations : {
    instructions_visual : 'Teipiwch y ddau air:',
    instructions_audio : 'Ysgrifennwch i lawr yr hyn yr ydych yn clywed:',
    play_again : 'Ailchwarae’r trac sain',
    cant_hear_this : 'Lawrlwythwch y trac mewn fformat MP3',
    visual_challenge : 'Modd gweledol',
    audio_challenge : 'Ddull clywedol',
    refresh_btn : 'Gofynnwch i ddau eiriau newydd',
    help_btn : 'Cymorth',
    incorrect_try_again : 'Anghywir. Os gwelwch yn dda ceisiwch eto.',
    image_alt_text : 'her image reCAPTCHA',
    privacy_and_terms : 'Preifatrwydd a Thelerau'
  },
  lang  : '".$params->get('lang', 'en')."'
};
      ";
} else 
  $script = "
var RecaptchaOptions = {
  theme : '".$params->get( 'theme', 'red' )."',
  lang  : '".$params->get( 'lang', 'en' )."'
};
  ";
}
This code first checks the current language set on the site. If the language tag is for Welsh $tag == 'cy-GB'
then it adds a JavaScript snippet with the Welsh language strings. Otherwise it adds the same JavaScript snippet as was used in the original file.
You can, of course replace the Welsh tag and translations with any other language that you need. If you need more than one additional language then you can use a 'switch' statement instead of the 'for . . . else' statement to include different JavaScript snippets.
Here's what the resulting ReCaptcha looks like:
ReCaptcha in Welsh
Note that the translations here are from Google Translate and may not be perfect! The Captcha words themselves are not affected by this change, nor is the audio version, or the Help texts which come from Google.

The default languages in ReCaptcha are English, Dutch, French, German, Portuguese, Russian, Spanish and Turkish.

 
Category: CFv4 Anti-spam

Comments:

You need to login to be able to post a comment.