1

The following piece of code implements error messages for recaptcha. The location is app/code/local/Magecomp/Recaptcha/Model/Observer.php

public function Customercreate($observer)
{

    try {

        if (Mage::helper('recaptcha/data')->showOnRegister()) {
             $g_response = Mage::app()->getRequest()->getParam('g-recaptcha-response');
            if (isset($g_response) && !empty($g_response)):
                if (!(Mage::helper('recaptcha')->Validate_captcha($g_response))):
                    Mage::getSingleton('core/session')->addError('Please click on the reCAPTCHA box.123');
                    $url = Mage::helper('core/http')->getHttpReferer() ? Mage::helper('core/http')->getHttpReferer() : Mage::getUrl();
                    Mage::app()->getFrontController()->getResponse()->setRedirect($url);
                    Mage::app()->getResponse()->sendResponse();
                    exit;
                endif;
            else:
                $observer->getEvent()->setData(null);
                Mage::getSingleton('core/session')->addError('Please click on the reCAPTCHA box.456');
                $url = Mage::helper('core/http')->getHttpReferer() ? Mage::helper('core/http')->getHttpReferer() : Mage::getUrl();
                Mage::app()->getFrontController()->getResponse()->setRedirect($url);
                Mage::app()->getResponse()->sendResponse();
                exit;
            endif;
        }
    } catch (Exception $e) {
        Mage::log("Captcha Error :" . $e->getMessage(), null, "recaptcha.log");
    }
}

How could I translate the texts "Please click on the reCAPTCHA box.123" and "Please click on the reCAPTCHA box.456" into another languages? I know that modifying core files is not recommended.

0

You need to add a translated string (or both) in the Magecomp Recaptcha Module translation file (should be app/locale/[your_LANG]/Magecomp_Recaptcha.csv) if there is one.

The translated string to add to the translation file for the italian language could be:

"Please click on the reCAPTCHA box.123","Si prega di cliccare sul reCAPTCHA box.123"
"Please click on the reCAPTCHA box.456","Si prega di cliccare sul reCAPTCHA box.456"

Then you have to edit the code in this way:

public function Customercreate($observer)
{

    try {

        if (Mage::helper('recaptcha/data')->showOnRegister()) {
             $g_response = Mage::app()->getRequest()->getParam('g-recaptcha-response');
            if (isset($g_response) && !empty($g_response)):
                if (!(Mage::helper('recaptcha')->Validate_captcha($g_response))):

                    Mage::getSingleton('core/session')->addError(Mage::helper('recaptcha/data')->__('Please click on the reCAPTCHA box.123'));

                    $url = Mage::helper('core/http')->getHttpReferer() ? Mage::helper('core/http')->getHttpReferer() : Mage::getUrl();
                    Mage::app()->getFrontController()->getResponse()->setRedirect($url);
                    Mage::app()->getResponse()->sendResponse();
                    exit;
                endif;
            else:
                $observer->getEvent()->setData(null);

                Mage::getSingleton('core/session')->addError(Mage::helper('recaptcha/data')->__('Please click on the reCAPTCHA box.456'));

                $url = Mage::helper('core/http')->getHttpReferer() ? Mage::helper('core/http')->getHttpReferer() : Mage::getUrl();
                Mage::app()->getFrontController()->getResponse()->setRedirect($url);
                Mage::app()->getResponse()->sendResponse();
                exit;
            endif;
        }
    } catch (Exception $e) {
        Mage::log("Captcha Error :" . $e->getMessage(), null, "recaptcha.log");
    }
}


I don't know the Magecomp_Recaptcha Module, but this module to supports translations need to setup a .csv translation file in the app/code/local/Magecomp/Recaptcha/etc/config.xml: look for the config/frontend/translate tag in this file. If there is no translation file setup, you need to add it:

<?xml version="1.0"?>
<config>
    [...]
    <frontend>
        <translate>
            <modules>
                <Magecomp_Recaptcha>
                    <files>
                        <default>Magecomp_Recaptcha.csv</default>
                    </files>
                </Magecomp_Recaptcha>
            </modules>
        </translate>
    </frontend>
    [...]
</config>

Then add the 2 rows below to your app/locale/[your_LANG]/Magecomp_Recaptcha.csv file.

0

Just go to your root directory and go to the following path:

/app/locale/de_DE

de_DE its for German you can go to the particular directory as per your store view.

Here, just open the Mage_Core.csv file and you can write the text like below example:

 "Please click on the reCAPTCHA box.123","Please click on the reCAPTCHA box.456"

Then flush your cache and check the frontend.

If you still face issue then try below code:

Just replace below code:

Mage::getSingleton('core/session')->addError('Please click on the reCAPTCHA box.123');

To

$errorMessage = Mage::helper('core')->__('Please click on the reCAPTCHA box.123');
Mage::getSingleton('core/session')->addError($errorMessage);

Let me know if you still face an issue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.