Translation of the form

As mentioned in previous chapters, the form is automatically linked to the translator. This eliminates a lot of annoying work and code writing.

What is automatically translated?

  • Field descriptions
  • Error messages
  • Any additional texts you need

What is not translated?

Only selection options, where there is a good chance that the values are already translated, or should not be translated at all. Thus, this is a situation where there is a risk of ambiguity. You have to take care of any translation of the selections.

Special situations

Of course, you may need to deal with certain special situations...

Switching off translation

If you want to disable translation on a particular form for some reason, you can do it like this:

$form->setDoNotTranslateTextstrue );

Imposing localisation

It may happen that you want to have the form in a different location than the current one. You can have multiple forms on a page, each in its own localization:

$custom_locale = new Locale('sk_SK');
$form->setCustomTranslatorLocale$custom_locale );

Imposing the dictionary

And last but not least, you may need to use a different compiler dictionary than the current one on the form. This is also not a problem:

$form->setCustomTranslatorDictionary'my.custom.dictionary' );

Translation according to the form

For example, you may need to translate text during validation, but according to the rules that apply to the form, which may be different from the current settings. You can do it like this:

$translated_text $form->_('Lorem ipsum dolor sit amet %some_value%', [ 'some_value'=>3.14 ]);
Previous chapter
Determining element widths
Next chapter
Mapping classes to forms