Name formats may be found in name_format.yml. Name formats are grouped by locale.
Example of format configuration for en_US:
en_US: %prefix% %first_name% %middle_name% %last_name% %suffix%
Possible format placeholders:
- prefix - name prefix
- first_name - first name
- middle_name - middle name
- last_name - last name
- suffix - name suffix
In case when format placeholder is in upper case corresponding value will be also upper cased.
Class: Oro\Bundle\LocaleBundle\Formatter\NameFormatter
Service id: oro_locale.formatter.name
Formats name based on given locale.
string public format(person[, string locale])
This method can be used to format objects that implements one of next interfaces:
- FirstNameInterface - defines getter for first name
- MiddleNameInterface - defines getter for middle name
- LastNameInterface - defines getter for last name
- NamePrefixInterface - defines getter for name prefix
- NameSuffixInterface - defines getter for name suffix
- FullNameInterface - extends FirstNameInterface, MiddleNameInterface, LastNameInterface, NamePrefixInterface and NameSuffixInterface
To format name using specific locale format locale parameters may be passed.
Format:
en_US: %prefix% %first_name% %middle_name% %LAST_NAME% %suffix%
Code:
$formatter = $container->get('oro_locale.formatter.name');
// Person implements FullNameInterface
$person->setNamePrefix('Mr.');
$person->setFirstName('First');
$person->setMiddleName('Middle');
$person->setLastName('Last');
$person->setNameSuffix('Sn.');
echo $formatter->format($person, 'en_US');
Outputs:
Mr. First Middle LAST Sn.
string public getNameFormat([string locale])
Get name format based on locale, if argument is not passed locale from system configuration will be used.
This filter use format method from name formatter, and has same logic.
{{ user|oro_format_name }}
string public format(Object person[, String locale])
This method can be used to format names. To format name using specific locale format locale parameters may be passed.
Possible name object parameters are same to format placeholder keys.
Usage example:
import nameFormatter from 'orolocale/js/formatter/name';
const formattedName = nameFormatter.format({
prefix: 'Mr.',
first_name: 'First',
middle_name: 'Middle',
last_name: 'Last',
suffix: 'Sn.'
});
string public getNameFormat([string locale])
Get name format based on locale, if argument is not passed locale from system configuration will be used.