-
-
Notifications
You must be signed in to change notification settings - Fork 150
[Intl] Add PHP 8.5 IntlListFormatter
to ICU 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
base: 1.x
Are you sure you want to change the base?
Conversation
fa352fc
to
3b446ce
Compare
// cc @BogdanUngureanu, I could use your inputs/review here :) |
]); | ||
} | ||
|
||
protected function getListPattern(): array { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not private?
src/Intl/Icu/IntlListFormatter.php
Outdated
private $width; | ||
|
||
protected static $listPatterns = [ | ||
'en' => [ |
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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.
This should be added in symfony/polyfill-intl-icu (with the other formatters) instead of being a new package IMO
Extending the internal class is not covered by BC and is not a supported use case. |
@Ayesh do you plan to finish this PR (by taking review comments into account) ? |
Thank you for your review Christophe. I will try and submit fixed addressing the reviewed points by this weekend. |
3b446ce
to
ad6b26c
Compare
IntlListFormatter
as installable polyfillIntlListFormatter
to ICU polyfill
0518c84
to
c888ccc
Compare
Thank you for your reviews. I changed the PR, so that this now proposes to add I also made it so that the class is self-contained, and not extendable anymore (making |
return strtr($pattern[2], ['{0}' => (string) $strings[0], '{1}' => (string) $strings[1]]); | ||
} | ||
|
||
if ($itemCount === 3) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could remove this case. It can be covered by the same code that for 4 items or more (the for
loop will simply do no iterations, which is not an error)
*/ | ||
class IntlListFormatterTest extends TestCase | ||
{ | ||
public function testUnsupportedLocales() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing support locales should be done in a separate test than testUnsupportedLocales
to make the intent of the tests clear.
Adds a new polyfill to `symfony/polyfill-intl-icu` that provides the functionality of the new `IntlListFormatter` to PHP 7.2 and later. - [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.
c888ccc
to
0156b53
Compare
Adds a new polyfill to
symfony/polyfill-intl-icu
that provides the functionality of the newIntlListFormatter
to PHP 7.2 and later.Closes GH-530.