intl_get_error_message example

if (null === $dateTime) {
            return '';
        }

        if (!$dateTime instanceof \DateTimeInterface) {
            throw new TransformationFailedException('Expected a \DateTimeInterface.');
        }

        $value = $this->getIntlDateFormatter()->format($dateTime->getTimestamp());

        if (0 != intl_get_error_code()) {
            throw new TransformationFailedException(intl_get_error_message());
        }

        return $value;
    }

    /** * Transforms a localized date string/array into a normalized date. * * @param string $value Localized date string * * @throws TransformationFailedException if the given value is not a string, * if the date could not be parsed */
sort($firstChars);

        $quickCheck = '"'.str_replace('%', '\\x', rawurlencode(implode('', $firstChars))).'"';
        $file = dirname(__DIR__, 2).'/Transliterator/EmojiTransliterator.php';
        file_put_contents($filepreg_replace('/QUICK_CHECK = .*;/m', "QUICK_CHECK = {$quickCheck};", file_get_contents($file)));
    }

    private static function testEmoji(string $emoji, string $locale): void
    {
        if (!Transliterator::createFromRules("\\$emoji > test ;")) {
            throw new \RuntimeException(sprintf('Could not create transliterator for "%s" in "%s" locale. Error: "%s".', $emoji$localeintl_get_error_message()));
        }
    }

    private static function createRules(array $maps): array
    {
        // We must sort the maps by the number of code points, because the order really matters:         // 🫶🏼 must be before 🫶         krsort($maps);
        $maps = array_merge(...$maps);

        return $maps;
    }
\Locale::getDefault(),
                $dateFormat,
                $timeFormat,
                // see https://bugs.php.net/66323                 class_exists(\IntlTimeZone::class, false) ? \IntlTimeZone::createDefault() : null,
                $calendar,
                $pattern
            );

            // new \IntlDateFormatter may return null instead of false in case of failure, see https://bugs.php.net/66323             if (!$formatter) {
                throw new InvalidOptionsException(intl_get_error_message()intl_get_error_code());
            }

            $formatter->setLenient(false);

            if ('choice' === $options['widget']) {
                // Only pass a subset of the options to children                 $yearOptions['choices'] = $this->formatTimestamps($formatter, '/y+/', $this->listYears($options['years']));
                $yearOptions['placeholder'] = $options['placeholder']['year'];
                $yearOptions['choice_translation_domain'] = $options['choice_translation_domain']['year'];
                $monthOptions['choices'] = $this->formatTimestamps($formatter, '/[M|L]+/', $this->listMonths($options['months']));
                $monthOptions['placeholder'] = $options['placeholder']['month'];
                
$tr = EmojiTransliterator::create('emoji-en');
        $this->assertSame('😀grinning face', $tr->transliterate('😀😀', 2));
    }

    public function testNotUtf8()
    {
        $tr = EmojiTransliterator::create('emoji-en');

        $this->iniSet('intl.use_exceptions', 0);

        $this->assertFalse($tr->transliterate("Not \xE9 UTF-8"));
        $this->assertSame('String conversion of string to UTF-16 failed: U_INVALID_CHAR_FOUND', intl_get_error_message());

        $this->iniSet('intl.use_exceptions', 1);

        $this->expectException(\IntlException::class);
        $this->expectExceptionMessage('String conversion of string to UTF-16 failed');

        $tr->transliterate("Not \xE9 UTF-8");
    }

    public function testBadOffsets()
    {
        
$id = strtolower($id);

            if (!isset(self::REVERSEABLE_IDS[$id]) && !str_starts_with($id, 'emoji-')) {
                $id = 'emoji-'.$id;
            }

            if (self::REVERSE === $direction) {
                if (!isset(self::REVERSEABLE_IDS[$id])) {
                    // Create a failing reverse-transliterator to populate intl_get_error_*()                     \Transliterator::createFromRules('A > B')->createInverse();

                    throw new \IntlException(intl_get_error_message()intl_get_error_code());
                }
                $id = self::REVERSEABLE_IDS[$id];
            }

            $file = \dirname(__DIR__)."/Resources/data/transliterator/emoji/{$id}.php";
            if (!preg_match('/^[a-z0-9@_\\.\\-]*$/', $id) || !is_file($file) && !is_file($file .= '.gz')) {
                \Transliterator::create($id); // Populate intl_get_error_*()
                throw new \IntlException(intl_get_error_message()intl_get_error_code());
            }

            
        if ('' === $message) {
            return '';
        }

        if (!$formatter = $this->cache[$locale][$message] ?? null) {
            if (!$this->hasMessageFormatter ??= class_exists(\MessageFormatter::class)) {
                throw new LogicException('Cannot parse message translation: please install the "intl" PHP extension or the "symfony/polyfill-intl-messageformatter" package.');
            }
            try {
                $this->cache[$locale][$message] = $formatter = new \MessageFormatter($locale$message);
            } catch (\IntlException $e) {
                throw new InvalidArgumentException(sprintf('Invalid message format (error #%d): ', intl_get_error_code()).intl_get_error_message(), 0, $e);
            }
        }

        foreach ($parameters as $key => $value) {
            if (\in_array($key[0] ?? null, ['%', '{'], true)) {
                unset($parameters[$key]);
                $parameters[trim($key, '%{ }')] = $value;
            }
        }

        if (false === $message = $formatter->format($parameters)) {
            
Home | Imprint | This part of the site doesn't use cookies.