public function getMessages(string $key, array $errors = []): array
    {
        // when there is a template for the given key, return only this message.
        if (array_key_exists($key, $this->templates)) {

            return [$this->translate($this->templates[$key], ['attribute' => $key])];

        }

        // return one message for each rule which failed.
        return array_reduce($errors, function ($messages, $error) use ($key) {

            $rule = $error->getRule();
            $parameters = $error->getParameters();

            $template = $this->getTemplate($key, $rule);

            $message = $this->translate($template, array_merge($parameters, [
                'attribute' => $key,
            ]));

            return array_merge($messages, [$message]);

        }, []);
    }