#41292·magento2

Customer Name validator messages bypass phrase translation

Author: atIOCrONCreated Sep 22, 2026Updated Sep 28, 2026
LabelsIssue: needs updateReported on 2.4.x

Preconditions and environment

  • Clean magento/magento2 checkout of 2.4-develop at efd7420a8d0758777032ee2f6fcc6c922d8bb3f9
  • PHP 8.5.10
  • Magento\Customer\Model\Validator\Name, which is registered for both customer and customer_address save validation in Magento_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

  1. Create a customer model whose first, middle, or last name contains a character rejected by Magento\Customer\Model\Validator\Name, for example First@.
  2. Run Name::isValid() with that model.
  3. Read the corresponding entry from Name::getMessages().
  4. Inspect the value type or render it under a locale which translates First Name is not valid!.

Equivalent minimal assertion:

php
$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:

php
'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.