From aa13b006de9afdf58a3bf3c568f351261e18d351 Mon Sep 17 00:00:00 2001 From: Jeroen De Dauw Date: Wed, 18 Jan 2023 00:38:12 +0100 Subject: [PATCH] Remove forced capitalization and match TWN changes --- src/EdtfFactory.php | 10 +++---- .../Humanizer/InternationalizedHumanizer.php | 3 -- ...FrenchStrategy.php => DefaultStrategy.php} | 4 +-- tests/Functional/EdtfFactoryTest.php | 2 +- tests/Functional/FrenchHumanizationTest.php | 30 +++++++++---------- 5 files changed, 23 insertions(+), 26 deletions(-) rename src/PackagePrivate/Humanizer/Strategy/{FrenchStrategy.php => DefaultStrategy.php} (63%) diff --git a/src/EdtfFactory.php b/src/EdtfFactory.php index a802987..43c50f8 100644 --- a/src/EdtfFactory.php +++ b/src/EdtfFactory.php @@ -12,7 +12,7 @@ use EDTF\PackagePrivate\Humanizer\InternationalizedHumanizer; use EDTF\PackagePrivate\Humanizer\PrivateStructuredHumanizer; use EDTF\PackagePrivate\Humanizer\Strategy\EnglishStrategy; -use EDTF\PackagePrivate\Humanizer\Strategy\FrenchStrategy; +use EDTF\PackagePrivate\Humanizer\Strategy\DefaultStrategy; use EDTF\PackagePrivate\Humanizer\Strategy\LanguageStrategy; use EDTF\PackagePrivate\SaneParser; use EDTF\PackagePrivate\Validator; @@ -73,10 +73,10 @@ private static function newMessageBuilder( private static function getLanguageStrategy( string $languageCode ): LanguageStrategy { switch ( $languageCode ) { - case "fr": - return new FrenchStrategy(); + case 'en': + return new EnglishStrategy(); + default: + return new DefaultStrategy(); } - - return new EnglishStrategy(); } } diff --git a/src/PackagePrivate/Humanizer/InternationalizedHumanizer.php b/src/PackagePrivate/Humanizer/InternationalizedHumanizer.php index 10e30d0..66add18 100644 --- a/src/PackagePrivate/Humanizer/InternationalizedHumanizer.php +++ b/src/PackagePrivate/Humanizer/InternationalizedHumanizer.php @@ -223,9 +223,6 @@ private function humanizeDateWithoutUncertainty( ExtDate $date ): string { if ( $month !== null ) { $month = $this->message( self::MONTH_MAP[$month] ); - if ( $day === null ) { - $month = ucfirst( $month ); - } } if ( $day !== null ) { diff --git a/src/PackagePrivate/Humanizer/Strategy/FrenchStrategy.php b/src/PackagePrivate/Humanizer/Strategy/DefaultStrategy.php similarity index 63% rename from src/PackagePrivate/Humanizer/Strategy/FrenchStrategy.php rename to src/PackagePrivate/Humanizer/Strategy/DefaultStrategy.php index bde3f20..101fc64 100644 --- a/src/PackagePrivate/Humanizer/Strategy/FrenchStrategy.php +++ b/src/PackagePrivate/Humanizer/Strategy/DefaultStrategy.php @@ -2,10 +2,10 @@ namespace EDTF\PackagePrivate\Humanizer\Strategy; -class FrenchStrategy implements LanguageStrategy { +class DefaultStrategy implements LanguageStrategy { public function applyOrdinalEnding( int $number ): string { - return $number === 1 ? $number . 'er' : (string)$number; + return (string)$number; } public function monthUppercaseFirst(): bool { diff --git a/tests/Functional/EdtfFactoryTest.php b/tests/Functional/EdtfFactoryTest.php index 1011aa0..2701654 100644 --- a/tests/Functional/EdtfFactoryTest.php +++ b/tests/Functional/EdtfFactoryTest.php @@ -24,7 +24,7 @@ public function testHumanizationEnglish(): void { public function testHumanizationFrench(): void { $this->assertSame( - 'Printemps 2021', + 'printemps 2021', EdtfFactory::newHumanizerForLanguage( 'fr' )->humanize( new Season( 2021, 21 ) ) ); } diff --git a/tests/Functional/FrenchHumanizationTest.php b/tests/Functional/FrenchHumanizationTest.php index fac516e..0053b46 100644 --- a/tests/Functional/FrenchHumanizationTest.php +++ b/tests/Functional/FrenchHumanizationTest.php @@ -13,31 +13,31 @@ * @covers \EDTF\PackagePrivate\Parser\Parser * @covers \EDTF\Model\Interval * @covers \EDTF\Model\IntervalSide - * @covers \EDTF\PackagePrivate\Humanizer\Strategy\FrenchStrategy + * @covers \EDTF\PackagePrivate\Humanizer\Strategy\DefaultStrategy */ class FrenchHumanizationTest extends TestCase { public function humanizationProvider(): Generator { - yield 'Interval year and month' => [ '2019-01/2021-02', 'De janvier 2019 à février 2021' ]; + yield 'Interval year and month' => [ '2019-01/2021-02', 'du janvier 2019 au février 2021' ]; yield 'Full date' => [ '1975-07-10', '10 juillet 1975' ]; yield 'Full date first day' => [ '1975-07-01', '1er juillet 1975' ]; - yield 'Year and month' => [ '1975-07', 'Juillet 1975' ]; + yield 'Year and month' => [ '1975-07', 'juillet 1975' ]; yield 'Year only' => [ '1975', '1975' ]; - yield 'Leading zeroes' => [ '0042', 'Année 42' ]; + yield 'Leading zeroes' => [ '0042', 'année 42' ]; - yield 'Interval with open end' => [ '2019/..', 'Depuis 2019 (fin indéterminée)' ]; - yield 'Interval with open start' => [ '../2021', 'Jusqu’à 2021' ]; - yield 'Interval with unknown end' => [ '2019/', 'Depuis 2019 jusqu’à une fin inconnue' ]; - yield 'Interval with unknown start' => [ '/2021', 'Depuis un début inconnu jusqu’à 2021' ]; + yield 'Interval with open end' => [ '2019/..', 'depuis le 2019 (fin indéterminée)' ]; + yield 'Interval with open start' => [ '../2021', '2021 ou antérieur' ]; + yield 'Interval with unknown end' => [ '2019/', 'depuis le 2019 jusqu’à une date inconnue' ]; + yield 'Interval with unknown start' => [ '/2021', 'depuis une date inconnue jusqu’àu 2021' ]; - yield 'Year approximate' => [ '2019~', 'Autour du 2019' ]; - yield 'Year uncertain' => [ '2019?', '2019 (incertain)' ]; - yield 'Year uncertain approximation' => [ '2019%', 'Autour du 2019 (incertain)' ]; + yield 'Year approximate' => [ '2019~', 'autour du 2019 (date approximative)' ]; + yield 'Year uncertain' => [ '2019?', '2019 (date incertaine)' ]; + yield 'Year uncertain approximation' => [ '2019%', 'autour du 2019 (date incertaine et approximative)' ]; - yield 'Month approximate' => [ '2019-04~', 'Autour du Avril 2019' ]; - yield 'Month uncertain' => [ '2019-04?', 'Avril 2019 (incertain)' ]; - yield 'Day approximate' => [ '2019-04-01~', 'Autour du 1er avril 2019' ]; - yield 'Day uncertain' => [ '2019-04-01?', '1er avril 2019 (incertain)' ]; + yield 'Month approximate' => [ '2019-04~', 'autour du avril 2019 (date approximative)' ]; + yield 'Month uncertain' => [ '2019-04?', 'avril 2019 (date incertaine)' ]; + yield 'Day approximate' => [ '2019-04-01~', 'autour du 1er avril 2019 (date approximative)' ]; + yield 'Day uncertain' => [ '2019-04-01?', '1er avril 2019 (date incertaine)' ]; yield 'Time with UTC' => [ '1985-04-12T23:20:30Z', '23:20:30 UTC 12 avril 1985' ]; yield 'Time with local time' => [ '1985-04-12T23:20:30', '23:20:30 (heure locale) 12 avril 1985' ];