Translations in form macro

Notice: This thread is very old.
Member | 67

Hi everyone,
I would like to have a translated form. I'm using pretty old version on Nette with Form macros from Jan Tvrdik (…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')}

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->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'))

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

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

Set it with setAttribute()

  $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)



Super, dakujem!

6 years ago