# How to translate webform messages?

**URL:** <https://forum.getkirby.com/t/how-to-translate-webform-messages/13870>\
**Category:** Questions\
**Tags:** v3\
**Created:** [April 21, 2019, 4:09pm UTC](https://forum.getkirby.com/t/how-to-translate-webform-messages/13870 "2019-04-21T16:09:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roman](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/roman/32/6571_2.png) [@Roman](https://forum.getkirby.com/u/Roman)\
**Post date:** [April 21, 2019, 4:09pm UTC](https://forum.getkirby.com/t/how-to-translate-webform-messages/13870/1 "2019-04-21T16:09:11Z")

</div>

Hi, would like to show messages depending on language [Contact form | Kirby CMS](https://getkirby.com/docs/cookbook/forms/basic-contact-form#the-contact-form-controller)

```
  $messages = [
        'name' => 'Please enter a valid name',
        'email' => 'Please enter a valid email address',
        'text' => 'Please enter a text between 3 and 3000 characters'
    ];

```

How can I translate “Please enter a valid name” and similar?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [April 21, 2019, 4:28pm UTC](https://forum.getkirby.com/t/how-to-translate-webform-messages/13870/2 "2019-04-21T16:28:21Z")

</div>

In a multi-language site, you can use the `translations` array in your language definition file to set translations:

`/site/languages/en.php

```auto
<?php

return [
    'code' => 'en',
    'default' => true,
    'direction' => 'ltr',
    'locale'. => [
        'en_US'
    ],
    'name' => 'English',
    'translations' => [
        'name' => 'Please enter a valid name',
        'email' => 'Please enter a valid email address',
        'text' => 'Please enter a text between 3 and 3000 characters'

    ],
    'url' => '/'
];

```

And so on for each language…

You can then use the `t()` helper to fetch these translations:

```auto
 $messages = [
    'name' => t('name'),
    'email' => t('email'),
    'text' => t('text')
];

```

- [https://getkirby.com/docs/guide/languages/custom-language-variables](https://getkirby.com/docs/guide/languages/custom-language-variables)
- [https://getkirby.com/docs/cookbook/i18n/using-variables-in-language-strings](https://getkirby.com/docs/cookbook/i18n/using-variables-in-language-strings)

---

<div class="post-metadata">

**Author:** ![Roman](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/roman/32/6571_2.png) [@Roman](https://forum.getkirby.com/u/Roman)\
**Post date:** [April 21, 2019, 4:38pm UTC](https://forum.getkirby.com/t/how-to-translate-webform-messages/13870/3 "2019-04-21T16:38:55Z")

</div>

Thank you, wasn’t sure about syntax here: ‘Please enter a valid name’, that it should be just t(‘name’) without anything else. Checked, all works fine. Only should be commas at the end of lines, right?

```auto
 $messages = [
    'name' => t('name'),
    'email' => t('email'),
    'text' => t('text')
];

```

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [April 21, 2019, 4:52pm UTC](https://forum.getkirby.com/t/how-to-translate-webform-messages/13870/4 "2019-04-21T16:52:39Z")

</div>

> [@Roman](#):
>
> Only should be commas at the end of lines, right?

Yes, of course.

You can set a fallback in case a message is not defined:

```auto
 'name' => t('name', 'The name field is required"),

```
