Kirby Uniform and multi language variables


I have setup the Kirby uniform plugin the “ajax way” with routing via the config.php and got everything working except for the error messages in multi languages. I have two languages on my site, Swedish and English and Swedish is the default.

This is a bit of code example from my config.php:

[ 'pattern' => '/(:all)',
        'method' => 'POST',
        'action' => function () {
            $form = new \Uniform\Form([
                'email' => [
                    'rules' => ['required', 'email'],
                    'message' => t('contact_form_error_email'),
                'recipient' => [
                  'rules' => ['required'],
                  'message' => t('contact_form_error_recipient'), 

As you can see I use language variables as error messages but it only works with the default language. When switching over to english on the website and trying again it still displays the default language swedish for error messages. I am using language variables all over the site and they all work except within this plugin.

Am I doing it wrong? I have tried to search for similiar problems in the forum but can’t find a solution. Hope someone can help.


It has to do with the loading order. You could try to load the language files like described here for Kirby 2: AJAX Mail Translation problem

Apart from that, your route doesn’t have any language context, so you would have to pass that along as well, I guess to load the correct language file.

I haven’t tested this, though)

Thanks texnixe for your quick answer!

Didnt get how to do it so I went another way and passed the standard error message that comes from the Uniform plugin (“email”, “message” etc) when you’re not setting the ‘message’ and substituted it via simple if statements in javascript at the template with the right language variable and it seems to work nice! :slight_smile:

Example code:

var handleError = function (response) {
    var errors = [];
    for (var key in response) {
        if (key == "email") { errors.push("<?= t('contact_form_error_email') ?>");}
        if (key == "name") { errors.push("<?= t('contact_form_error_name') ?>");}
        if (key == "message") { errors.push("<?= t('contact_form_error_message') ?>");}
    message.innerHTML = errors.join('');