1

I am working on one custom module to alter the fields labels of user login form for visitors. I created a module to alter the labels in the user login form. The French language is enabled on the setup.

I am trying to translate the field labels on the user login form to French. I am using the following approach in a module.

I have included the namespace with use Drupal\Core\StringTranslation. After that, I have debugged the $form variable inside hook_form_alter().

From this debugged variable, I am trying to translate the filed label 'E-mail' to French.

function hook_form_alter ({here goes all the parameters of alter hooks}){
  $form['name']['#title'] = t('E-mail');
}

I am not able to see the translated Email field label on the user login form.

Am I missing anything? What should I do to translate the strings using hook_form_alter()?

1
0

you have find and add your translation string here : admin/config/regional/translate

1
  • Thanks, this is working. But If i want to do it by including name space then which one I can include? Feb 1 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.