Recaptcha翻译

时间:2013-04-19 09:30:48

标签: javascript captcha recaptcha

我正在尝试使用reCAPTCHA.net的验证码服务,但我想使用自定义翻译(https://developers.google.com/recaptcha/docs/customization#i18n),因为内置的翻译不涵盖所有语言。此外,我不想使用他们的标准主题之一,我想完全自定义以匹配验证码的外观到我的网站。

以下是我正在尝试的内容的片段,但是由于一些有趣的原因它无法正常工作(文本保留为英文而不是翻译)。我想知道“Get another Captcha”,“获取音频Captcha”,“帮助”等文本链接是否会翻译。如果我理解正确,这些应该转换,具体取决于我在custom_translations属性中设置的字符串。另外,如果我用图标而不是文本替换文本链接的内容,图标会自动获得带有适当内容的ALT标记吗?

所以,例如,如果我改变了这个:

<div class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type('audio')">Get an audio CAPTCHA</a></div>

为此,图像的alt标签是否会自动预先填充,以便当您将鼠标悬停在图标上时会显示“获取音频验证码”?

<div class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type('audio')"><img height="16" width="16" src="audio.gif" alt="" /></a></div>

我问这个问题,因为当我尝试选择其中一个标准主题时,例如`theme:'red',alt标签会根据语言自动翻译。

以下是我的代码片段。我从下面删除了我的公钥。

JS

<script type="text/javascript">
    var RecaptchaOptions = {
            custom_translations : {
                    instructions_visual : "Scrivi le due parole:",
                    instructions_audio : "Trascrivi ci\u00f2 che senti:",
                    play_again : "Riascolta la traccia audio",
                    cant_hear_this : "Scarica la traccia in formato MP3",
                    visual_challenge : "Modalit\u00e0 visiva",
                    audio_challenge : "Modalit\u00e0 auditiva",
                    refresh_btn : "Chiedi due nuove parole",
                    help_btn : "Aiuto",
                    incorrect_try_again : "Scorretto. Riprova.",
            },
            lang : 'it', // Unavailable while writing this code (just for audio challenge)
            theme : 'custom', // Make sure there is no trailing ',' at the end of the RecaptchaOptions dictionary
      custom_theme_widget: 'recaptcha_widget'
    };
</script>

HTML

<div id="recaptcha_widget" style="display:none">

<div id="recaptcha_image"></div>
<div class="recaptcha_only_if_incorrect_sol" style="color:red">Incorrect please try again</div>

<span class="recaptcha_only_if_image">Enter the words above:</span>
<span class="recaptcha_only_if_audio">Enter the numbers you hear:</span>

<input type="text" id="recaptcha_response_field" name="recaptcha_response_field" />

<div><a href="javascript:Recaptcha.reload()">Get another CAPTCHA</a></div>
<div class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type('audio')">Get an audio CAPTCHA</a></div>
<div class="recaptcha_only_if_audio"><a href="javascript:Recaptcha.switch_type('image')">Get an image CAPTCHA</a></div>

<div><a href="javascript:Recaptcha.showhelp()">Help</a></div>

</div>

 <script type="text/javascript"
src="http://www.google.com/recaptcha/api/challenge?k=MY_PUBLIC_KEY">
 </script>
 <noscript>
 <iframe src="http://www.google.com/recaptcha/api/noscript?k=MY_PUBLIC_KEY"
    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>

我还附上了结果的截图 enter image description here

1 个答案:

答案 0 :(得分:0)

据我了解,如果您使用自己的HTML模板,则不会使用custom_translations JavaScript对象。在这种情况下,您必须使用与应用程序其余部分相同的本地化进行手动翻译。如果您不自己提供HTML,则使用custom_translations,而是使用其中一个预定义的主题。