Search code examples
octobercmsoctobercms-pluginsoctober-form-controller

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');
}

Solution

  • 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.