Skip to content

[Intl] Add PHP 8.5 IntlListFormatter as installable polyfill #532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 1.x
Choose a base branch
from

Conversation

Ayesh
Copy link
Contributor

@Ayesh Ayesh commented Jun 28, 2025

Adds a new polyfill component symfony/polyfill-intl-listformatter that provides the functionality of the new IntlListFormatter to PHP 7.2 and later.

It is a new composer-installable package (similar to how Intl MessageFormatter is a separate installable package, and the PHP 8.5 polyfill can require it as a dependency too.

It only supports en locale. However, PHP applications that require this package can extend the namespaced polyfill
(\Symfony\Polyfill\Intl\ListFormatter\IntlListFormatter) and add their own list patterns by extending the static variable (\Symfony\Polyfill\Intl\ListFormatter\IntlListFormatter::$listPatterns) that holds these patterns.

Closes GH-530.

@Ayesh Ayesh force-pushed the feat/intllistformatter branch from fa3be1e to fa352fc Compare June 28, 2025 19:15
Adds a new polyfill component `symfony/polyfill-intl-listformatter`
that provides the functionality of the new `IntlListFormatter` to
PHP 7.2 and later.

It is a new composer-installable package (similar to how Intl
`MessageFormatter` is a separate installable package, and the PHP 8.5
polyfill can require it as a dependency too.

It only supports `en` locale. However, PHP applications that require
this package can extend the namespaced polyfill
(`\Symfony\Polyfill\Intl\ListFormatter\IntlListFormatter`) and add
their own list patterns by extending the static variable (`\Symfony\Polyfill\Intl\ListFormatter\IntlListFormatter::$listPatterns`)
that holds these patterns.

 - [ICU listPatterns](https://github.com/unicode-org/cldr-json/blob/main/cldr-json/cldr-misc-full/main/en/listPatterns.json)
 - [php-src commit](php/php-src@3f7545245)
 - [PHP.Watch: IntlListFormatter](https://php.watch/versions/8.5/IntlListFormatter)

Closes symfonyGH-530.
@Ayesh Ayesh force-pushed the feat/intllistformatter branch from fa352fc to 3b446ce Compare June 28, 2025 19:17
@Ayesh
Copy link
Contributor Author

Ayesh commented Jun 28, 2025

// cc @BogdanUngureanu, I could use your inputs/review here :)

*
* @internal
*/
class IntlListFormatter

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be final, non-serializable and not able to clone it.

]);
}

protected function getListPattern(): array {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not private?

private $width;

protected static $listPatterns = [
'en' => [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make it clear that this is en_US since it's using the Oxford comma?

) {
$exceptionClass = PHP_VERSION_ID >= 80000 ? \ValueError::class : \InvalidArgumentException::class;
if ($locale !== 'en' && strpos($locale, 'en') !== 0) {
throw new $exceptionClass('Invalid locale, only "en" and "en-*" locales are supported');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some mixed feelings about this. Since it's using the en-US set, for en-gb it would return a different result than the real class.

@stof
Copy link
Member

stof commented Jun 30, 2025

This should be added in symfony/polyfill-intl-icu (with the other formatters) instead of being a new package IMO

It only supports en locale. However, PHP applications that require this package can extend the namespaced polyfill
(\Symfony\Polyfill\Intl\ListFormatter\IntlListFormatter) and add their own list patterns by extending the static variable (\Symfony\Polyfill\Intl\ListFormatter\IntlListFormatter::$listPatterns) that holds these patterns.

Extending the internal class is not covered by BC and is not a supported use case.
Projects wanting the full support for ICU formatting should install ext-intl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add IntlListFormatter
3 participants