diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -525,6 +525,7 @@ 'phutil_loggable_string' => 'utils/utils.php', 'phutil_parse_bytes' => 'utils/viewutils.php', 'phutil_passthru' => 'future/exec/execx.php', + 'phutil_person' => 'internationalization/pht.php', 'phutil_register_library' => 'moduleutils/core.php', 'phutil_register_library_map' => 'moduleutils/core.php', 'phutil_safe_html' => 'markup/render.php', diff --git a/src/internationalization/PhutilLocale.php b/src/internationalization/PhutilLocale.php --- a/src/internationalization/PhutilLocale.php +++ b/src/internationalization/PhutilLocale.php @@ -47,7 +47,7 @@ * @return string Variant for use. */ public function selectGenderVariant($variant, array $translations) { - if ($variant == PhutilPerson::SEX_FEMALE) { + if ($variant == PhutilPerson::GENDER_FEMININE) { return end($translations); } else { return reset($translations); diff --git a/src/internationalization/PhutilPerson.php b/src/internationalization/PhutilPerson.php --- a/src/internationalization/PhutilPerson.php +++ b/src/internationalization/PhutilPerson.php @@ -1,10 +1,11 @@ getNumber(); } else if ($variant instanceof PhutilPerson) { - $is_sex = true; - $variant = $variant->getSex(); + $is_gender = true; + $variant = $variant->getGender(); } else if (is_int($variant)) { - $is_sex = false; + $is_gender = false; } else { return null; } - if ($is_sex) { + if ($is_gender) { return $this->locale->selectGenderVariant($variant, $translations); } else { diff --git a/src/internationalization/__tests__/PhutilPersonTest.php b/src/internationalization/__tests__/PhutilPersonTest.php --- a/src/internationalization/__tests__/PhutilPersonTest.php +++ b/src/internationalization/__tests__/PhutilPersonTest.php @@ -2,19 +2,19 @@ final class PhutilPersonTest extends Phobject implements PhutilPerson { - private $sex = PhutilPerson::SEX_UNKNOWN; + private $gender = PhutilPerson::GENDER_UNKNOWN; - public function getSex() { - return $this->sex; + public function getGender() { + return $this->gender; } - public function setSex($value) { - $this->sex = $value; + public function setGender($value) { + $this->gender = $value; return $this; } public function __toString() { - return pht('Test (%s)', $this->sex); + return pht('Test (%s)', $this->gender); } } diff --git a/src/internationalization/__tests__/PhutilTranslatorTestCase.php b/src/internationalization/__tests__/PhutilTranslatorTestCase.php --- a/src/internationalization/__tests__/PhutilTranslatorTestCase.php +++ b/src/internationalization/__tests__/PhutilTranslatorTestCase.php @@ -79,12 +79,12 @@ 'Test () napsal.', $translator->translate('%s wrote.', $person)); - $person->setSex(PhutilPerson::SEX_MALE); + $person->setGender(PhutilPerson::GENDER_MASCULINE); $this->assertEqual( 'Test (m) napsal.', $translator->translate('%s wrote.', $person)); - $person->setSex(PhutilPerson::SEX_FEMALE); + $person->setGender(PhutilPerson::GENDER_FEMININE); $this->assertEqual( 'Test (f) napsala.', $translator->translate('%s wrote.', $person)); diff --git a/src/internationalization/pht.php b/src/internationalization/pht.php --- a/src/internationalization/pht.php +++ b/src/internationalization/pht.php @@ -31,3 +31,16 @@ return new PhutilNumber(count($countable)); } + +/** + * Provide a gendered argument to the translation engine. + * + * This function does nothing and only serves as a marker for the static + * extractor so it knows particular arguments may vary on gender. + * + * @param PhutilPerson Something implementing @{interface:PhutilPerson}. + * @return PhutilPerson The argument, unmodified. + */ +function phutil_person(PhutilPerson $person) { + return $person; +}