Convert a GEDCOM age string to localized text.

@param string $age_string

@return string
176044
public static function getAgeAtEvent(string $age_string): string
    {
        switch (strtoupper($age_string)) {
            case 'CHILD':
                return I18N::translate('Child');
            case 'INFANT':
                return I18N::translate('Infant');
            case 'STILLBORN':
                return I18N::translate('Stillborn');
            default:
                return preg_replace_callback(
                    [
                        '/(\d+)([ymwd])/',
                    ],
                    static function (array $match): string {
                        $num = (int) $match[1];

                        switch ($match[2]) {
                            case 'y':
                                return I18N::plural('%s year', '%s years', $num, I18N::number($num));
                            case 'm':
                                return I18N::plural('%s month', '%s months', $num, I18N::number($num));
                            case 'w':
                                return I18N::plural('%s week', '%s weeks', $num, I18N::number($num));
                            case 'd':
                                return I18N::plural('%s day', '%s days', $num, I18N::number($num));
                            default:
                                throw new LogicException('Should never get here');
                        }
                    },
                    $age_string
                );
        }
    }
873472
public function asText(): string
    {
        if ($this->keyword === self::KEYWORD_STILLBORN) {
            // I18N: An individual’s age at an event. e.g. Died 14 Jan 1900 (stillborn)
            return I18N::translate('(stillborn)');
        }

        if ($this->keyword === self::KEYWORD_INFANT) {
            // I18N: An individual’s age at an event. e.g. Died 14 Jan 1900 (in infancy)
            return I18N::translate('(in infancy)');
        }

        if ($this->keyword === self::KEYWORD_CHILD) {
            // I18N: An individual’s age at an event. e.g. Died 14 Jan 1900 (in childhood)
            return I18N::translate('(in childhood)');
        }

        $age = [];

        // Show a zero age as "0 years", not "0 days"
        if ($this->years > 0 || $this->months === 0 && $this->weeks === 0 && $this->days === 0) {
            // I18N: Part of an age string. e.g. 5 years, 4 months and 3 days
            $age[] = I18N::plural('%s year', '%s years', $this->years, I18N::number($this->years));
        }

        if ($this->months > 0) {
            // I18N: Part of an age string. e.g. 5 years, 4 months and 3 days
            $age[] = I18N::plural('%s month', '%s months', $this->months, I18N::number($this->months));
        }

        if ($this->weeks > 0) {
            // I18N: Part of an age string. e.g. 5 years, 4 months and 3 days
            $age[] = I18N::plural('%s week', '%s weeks', $this->weeks, I18N::number($this->weeks));
        }

        if ($this->days > 0) {
            // I18N: Part of an age string. e.g. 5 years, 4 months and 3 days
            $age[] = I18N::plural('%s day', '%s days', $this->days, I18N::number($this->days));
        }

        // If an age is just a number of years, only show the number
        if ($this->years > 0 && $this->months === 0 && $this->weeks === 0 && $this->days === 0) {
            $age = [I18N::number($this->years)];
        }

        $age_string = implode(I18N::$list_separator, $age);

        if ($this->qualifier === self::SYMBOL_LESS_THAN) {
            // I18N: Description of an individual’s age at an event. For example, Died 14 Jan 1900 (aged less than 21 years)
            return I18N::translate('(aged less than %s)', $age_string);
        }

        if ($this->qualifier === self::SYMBOL_MORE_THAN) {
            // I18N: Description of an individual’s age at an event. For example, Died 14 Jan 1900 (aged more than 21 years)
            return I18N::translate('(aged more than %s)', $age_string);
        }

        // I18N: Description of an individual’s age at an event. For example, Died 14 Jan 1900 (aged 43 years)
        return I18N::translate('(aged %s)', $age_string);
    }
714653
public function generateString($string = '', $placeholders = [])
    {
        $string = addslashes($string);
        if ($this->enableI18N) {
            // If there are placeholders, use them
            if (!empty($placeholders)) {
                $ph = ', ' . VarDumper::export($placeholders);
            } else {
                $ph = '';
            }
            $str = "Yii::t('" . $this->messageCategory . "', '" . $string . "'" . $ph . ")";
        } else {
            // No I18N, replace placeholders by real words, if any
            if (!empty($placeholders)) {
                $phKeys = array_map(function($word) {
                    return '{' . $word . '}';
                }, array_keys($placeholders));
                $phValues = array_values($placeholders);
                $str = "'" . str_replace($phKeys, $phValues, $string) . "'";
            } else {
                // No placeholders, just the given string
                $str = "'" . $string . "'";
            }
        }
        return $str;
    }
1203993
public function translate($string, &$num) {
        if ($this->short_circuit)
            return $string;
        $this->load_tables();

        if ($this->enable_cache) {
            // Caching enabled, get translated string from cache
            if (array_key_exists($string, $this->cache_translations))
                return $this->cache_translations[$string];
            else
                return $string;
        }
        else {
            // Caching not enabled, try to find string
            $num = $this->find_string($string);
            if ($num == -1)
                return $string;
            else
                return $this->get_translation_string($num);
        }
    }
574178
public function convert(string $string): string
    {
        if ($this->encoding === null) {
            $this->encoding = $this->getEncoding($string);
        }

        if ($this->encoding === self::UTF16BE) {
            $string = mb_convert_encoding($string, "UTF-8", "UTF-16BE");
        }

        if ($this->encoding === self::UTF16LE) {
            $string = mb_convert_encoding($string, "UTF-8", "UTF-16LE");
        }

        return $string;
    }
1087795
private function extractNumber(string $age, string $suffix): int
    {
        if (preg_match('/(\d+) *' . $suffix . '/', $age, $match)) {
            return (int) $match[1];
        }

        return 0;
    }
1025348
public void parse(String version_string) {
        _version = 0;
        _revision = 0;
        _subrevision = 0;
        _suffix = "";
        int pos = 0;
        int startpos = 0;
        int endpos = version_string.length();
        while ( (pos < endpos) && Character.isDigit(version_string.charAt(pos))) {
            pos++;
        }
        _version = Integer.parseInt(version_string.substring(startpos,pos));
        if ((pos < endpos) && version_string.charAt(pos)=='.') {
            startpos = ++pos;
            while ( (pos < endpos) && Character.isDigit(version_string.charAt(pos))) {
                pos++;
            }
            _revision = Integer.parseInt(version_string.substring(startpos,pos));
        }
        if ((pos < endpos) && version_string.charAt(pos)=='.') {
            startpos = ++pos;
            while ( (pos < endpos) && Character.isDigit(version_string.charAt(pos))) {
                pos++;
            }
            _subrevision = Integer.parseInt(version_string.substring(startpos,pos));
        }
        if (pos < endpos) {
            _suffix = version_string.substring(pos);
        }
    }
79653
private function ageBetweenSiblingsAge(int $total): string
    {
        $rows = $this->ageBetweenSiblingsQuery($total);

        foreach ($rows as $fam) {
            return $this->calculateAge((int) $fam->age);
        }

        return '';
    }
1307101
public static function detransliterateString($string, $after_safe_mode = false)
    {
        return \str_replace(
            $after_safe_mode === true
                ? static::$latin_safe_analogs
                : static::$latin_analogs,
            static::$cyr_chars,
            (string) $string
        );
    }
198158
public static function convertToUtf8(string $string): string
    {
        // If it's already a UTF8 string, just clean and return it
        if (static::isUtf8($string)) {
            return HtmlPurifier::cleanUtf8($string);
        }

        // Otherwise set HTMLPurifier to the actual string encoding
        $config = \HTMLPurifier_Config::createDefault();
        $config->set('Core.Encoding', static::encoding($string));

        // Clean it
        $string = HtmlPurifier::cleanUtf8($string);

        // Convert it to UTF8 if possible
        if (function_exists('iconv') && \HTMLPurifier_Encoder::testIconvTruncateBug() === \HTMLPurifier_Encoder::ICONV_OK) {
            $string = HtmlPurifier::convertToUtf8($string, $config);
        } else {
            $encoding = static::encoding($string);
            $string = mb_convert_encoding($string, 'utf-8', $encoding);
        }

        return $string;
    }
783286
protected function formatCommandString($string)
    {
        if (Eye::laravelVersionIs('>=', '5.4.0')) {
            return Application::formatCommandString($string);
        }

        return sprintf('%s %s %s', $this->phpBinary(), $this->artisanBinary(), $string);
    }
348285
public static function transliterateString($string, $safe_mode = false)
    {
        $string = (string) $string;

        if ($safe_mode === true) {
            $string = \str_replace(
                static::$cyr_chars,
                static::$latin_safe_analogs,
                $string
            );
        }

        return Str::ascii($string);
    }
691213
public static function low($string): string
    {
        if (self::isMBString()) {
            return mb_strtolower($string, self::$encoding);
        }

        return strtolower($string); // @codeCoverageIgnore
    }
317675
public static function commonConvertEncode($string, $to_encoding = 'utf-8', $utf8_first = true)
    {
        $encoding_list = [
            "ASCII", 'UTF-8', "GB2312", "GBK", 'BIG5',
        ];

        if (! $utf8_first) {
            $encoding_list = [
                "ASCII", "GB2312", "GBK", 'UTF-8', 'BIG5',
            ];
        }

        $from_encoding = mb_detect_encoding($string, $encoding_list);

        return mb_convert_encoding(trim($string), $to_encoding, $from_encoding);
    }
575449
public function fromSqlToIso8601Time(string $string, ?DateTimeZone $displayedTimeZone = null): string
    {
        $dateTime = DateTime::createFromFormat(
            "Y-m-d H:i:s",
            $string,
            $displayedTimeZone
        );

        if ($dateTime === false) {
            return "";
        }

        return $dateTime->format(DateTime::ATOM);
    }
125096
public static function localizeDate($string)
    {
        // Only translate dates in localized environments
        if (self::isLocalized()) {
            foreach (self::$_datetime_dictionary as $value) {
                $string = preg_replace('/\b' . $value . '\b/i', self::translate($value), $string);
            }
        }

        return $string;
    }
510811
function gettext($string)
    {
        global $PPHP;
        $req = grab('request');

        $default = $PPHP['config']['global']['default_lang'];
        $current = $req['lang'];

        $res = $string;
        try {
            if (self::$_gettext !== null) {
                $res = self::$_gettext->gettext($string);
            };
        } catch (\Exception $e) {
            echo $e->getMessage();
        };
        return $res;
    }