Translations in form macro

Notice: This thread is very old.
tomolas
Member | 66
+
0
-

Hi everyone,
I would like to have a translated form. I'm using pretty old version on Nette with Form macros from Jan Tvrdik (https://gist.github.com/…vrdik/435631). I would like to do something like this:

{form logInForm}
	{input username "placeholder" => _("login-form-placeholder-email")}
	{input password "placeholder" => _('login-form-placeholder-password')}
	...
{/form}

The outcome doesn't get translated. How would you solve this?

Translator is set correctly and works for cases like this as well as in templates:

	protected function createComponentLogInForm()
	{
		$form = new AppForm();
		$form->setTranslator($this->translator);
		$form->addText('username', _('login-form-email'))
			->addRule(AppForm::FILLED, _('login-form-email-error'));

		$form->addPassword('password', _('login-form-password'))
			->addRule(AppForm::FILLED, _('login-form-password-error'));

		$form->addCheckbox('remember', _('login-form-remember'))
			->setValue(1);

		$form->addSubmit('login', _('login-form-login-btn'));

		$form->onSubmit[] = callback($this, 'logInFormSubmitted');
		return $form;
	}
jixis
Member | 4
+
0
-

Set it with setAttribute()

<?php
  $form->addText('username', 'login-form-email')
	->setAttribute('placeholder', _('placeholder'))
        ->addRule(AppForm::FILLED, 'login-form-email-error');
?>

Note: If You set translator to form, it will translate error messages and labels (You don't need to use translator explicitly – but attributes aren't translated)

Last edited by jixis (2014-07-14 14:20)

tomolas
Member | 66
+
0
-

Super, dakujem!