Customer Name validator messages bypass phrase translation
Preconditions and environment
- Clean
magento/magento2checkout of2.4-developatefd7420a8d0758777032ee2f6fcc6c922d8bb3f9 - PHP 8.5.10
Magento\Customer\Model\Validator\Name, which is registered for bothcustomerandcustomer_addresssave validation inMagento_Customer/etc/validation.xml
Telephone, City, and Street already return translated Magento\Framework\Phrase messages on current 2.4-develop. Name is the remaining validator in this group which returns raw strings.
Steps to reproduce
- Create a customer model whose first, middle, or last name contains a character rejected by
Magento\Customer\Model\Validator\Name, for exampleFirst@. - Run
Name::isValid()with that model. - Read the corresponding entry from
Name::getMessages(). - Inspect the value type or render it under a locale which translates
First Name is not valid!.
Equivalent minimal assertion:
$validator->isValid($customerWithInvalidName);
$message = $validator->getMessages()[0]['firstname'];
self::assertInstanceOf(\Magento\Framework\Phrase::class, $message);Expected result
Invalid first-, middle-, and last-name messages are created through __() and returned as Magento\Framework\Phrase values. Their existing English text remains unchanged and translations can be applied consistently with the other customer-address validators.
Actual result
Name adds three raw string literals directly to the validation message collection:
'First Name is not valid!'
'Last Name is not valid!'
'Middle Name is not valid!'The assertion above fails because the value is a string. Since the literals do not pass through __(), this validation path bypasses Magento phrase translation and displays the English fallback even when a matching locale translation exists.
Additional information
This is now a narrow Name validator issue. The related Telephone, City, and Street messages were converted to Phrase values by the address-validator refactor already present on 2.4-develop (including commit 058d76ee190ae554439610111836d17065be3202).
The proposed fix only wraps the three existing messages in __(). It does not change validation rules, accepted characters, requiredness, or message text.
Focused verification on the clean checkout after the fix:
NameTest: 5 tests, 16 assertions, all passing on PHP 8.5.10.- Magento PHP coding standard: passing for the changed source and test.
Release note
Made customer first-, middle-, and last-name validation errors translatable and consistent with other customer-address validation messages.
Triage and priority
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
Source: magento/magento2