1

I am trying to change the label for Craft's form errors. My site local is currently fr_CA, and when I try to submit a form with an error, the error message returned is in french, but the label of the field is in english.

I have managed to translate field labels for plugins, such as the Contact Form plugin by P&T, without any issues by using static translations. All I simply did was create a file with the plugin translation category as a name such as 'contact-form.php' and it works flawlessly.

However, with the forms included in Craft, it doesn't seem to work. For example, with the user registration form, if I submit it without a password, it will come up with an error saying the password needs to have at least 6 characters. Here is the message I receive :

New Password doit comporter au moins 6 caractères.

The 'New Password' is in english while the rest of the message is in french.

If I try to create a file called 'site.php' or 'app.php' in the translations folder under the right locale, it doesn't translate the 'New Password'. Here is the content of the file :

<?php

return [
    'New Password' => 'Nouveau mot de passe'
];

It's like none of the translations supplied to Craft are being recognized. Has anyone run into this problem or have a solution?

2

You can't translate that field. I've tried it too once but it can't be done right now without effort because craft\elements\Userhas no attributeLabels() function in it in order to translate the attribute so all Yii2 does is to change newPassword to New Password but it doesn't translate anything.

You can either submit a feature request for it or do some hacky stuff.

I submitted a feature request in their git

Edit 13.08.2018 This commit changed it, you'll be able to translate those messages now

|improve this answer|||||
  • Thank you @robinschambach for the information. Good on you for the feature request, this definitely needs to be addressed. Since I am using Ajax to submit the form and display errors, I think I will resort to a simple find and replace in Javascript to translate those fields before displaying the error messages. – Rhys Halsey Aug 13 '18 at 17:47

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.