Ad

Octobercms: How To Translate Flash Messages?

I use translate.rainlab plugin for localization, but not sure how to translate flash messages for ajax form.

function onMailSend() {
    Mail::sendTo('[email protected]', 'contact.form', post());
    Flash::success('Message has been sent');
}
Ad

Answer

You can stick with using the Translate plugin's features, no need to use another translation mechanism.

use RainLab\Translate\Models\Message;

function onMailSend() {
    Mail::sendTo('[email protected]', 'contact.form', post());
    Flash::success(Message::trans('Message has been sent'));
}

This assumes that "Message has been sent" is the string in the default locale.

Ad
source: stackoverflow.com
Ad