Add function for assembling display names by given name and family name
This commit is contained in:
parent
bde3c2cb9e
commit
6dcdb3aff6
@ -69,6 +69,25 @@ final class NodaNameSplitter {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Assembles first name and given name into a common name as pronounced in the given language.
|
||||
*
|
||||
* @param string $givenName Given name of the actor.
|
||||
* @param string $familyName Family name of the actor.
|
||||
* @param string $toAdd Additional information to add to the name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function assembleNameParts(string $givenName, string $familyName, string $toAdd = ''):string {
|
||||
|
||||
if (in_array($this->_lang, self::LANGS_FAMILY_NAME_FIRST, true)) {
|
||||
return trim($familyName) . ' ' . trim($givenName) . $toAdd;
|
||||
}
|
||||
|
||||
return trim($givenName . ' ' . $familyName) . $toAdd;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
@ -43,4 +43,23 @@ final class NodaNameSplitterTest extends TestCase {
|
||||
self::assertEquals($splitter->givenNameFamilyNameFromString('Filomeno V. Aguilar, Jr.'), ['family_name' => 'Filomeno', 'given_name' => 'V. Aguilar, Jr.']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the assembly of full names based on given name and family name.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
* @group ValidOutput
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAssembleNameParts():void {
|
||||
|
||||
$splitter = new NodaNameSplitter('de');
|
||||
// This applied to all languages
|
||||
self::assertEquals($splitter->assembleNameParts('Friedrich', 'Wilhelm', ' (1910-1920)'), 'Friedrich Wilhelm (1910-1920)');
|
||||
|
||||
$splitter = new NodaNameSplitter('hu');
|
||||
self::assertEquals($splitter->assembleNameParts('Friedrich', 'Wilhelm'), "Wilhelm Friedrich");
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user