public function getLocalizedName()

in app/Models/Relationship/RelationshipType.php [73:118]


    public function getLocalizedName(Contact $contact = null, bool $includeOpposite = false, string $gender = null)
    {
        $defaultGender = AccountHelper::getDefaultGender($this->account);

        if (is_null($gender)) {
            $gender = $defaultGender;
        }

        $femaleVersion = trans('app.relationship_type_'.$this->name.'_female');
        $maleVersion = trans('app.relationship_type_'.$this->name);

        if (! is_null($contact)) {
            $maleVersionWithName = trans('app.relationship_type_'.$this->name.'_with_name', ['name' => $contact->name]);
            $femaleVersionWithName = trans('app.relationship_type_'.$this->name.'_female_with_name', ['name' => $contact->name]);

            // include the reverse of the relation in the string (masculine/feminine)
            // this is used in the dropdown of the relationship types when creating
            // or deleting a relationship.
            if ($includeOpposite) {
                // in some language, masculine and feminine version of a relationship type is the same.
                // we need to keep just one version in that case.
                if ($femaleVersion === $maleVersion) {
                    // `Regis Freyd's significant other`
                    return $maleVersionWithName;
                }

                return $defaultGender === Gender::FEMALE ?
                    // `Regis Freyd's aunt/uncle`
                    $femaleVersionWithName.'/'.$maleVersion :
                    // `Regis Freyd's uncle/aunt`
                    $maleVersionWithName.'/'.$femaleVersion;
            } else {
                return $gender === Gender::FEMALE ?
                    // `Regis Freyd's aunt`
                    $femaleVersionWithName :
                    // `Regis Freyd's uncle`
                    $maleVersionWithName;
            }
        }

        return $gender === Gender::FEMALE ?
            // `aunt`
            $femaleVersion :
            // `uncle`
            $maleVersion;
    }