From e08d522e5e6fa3ed6ff6cfc07d9a37744706077b Mon Sep 17 00:00:00 2001 From: "jg.trescazes" Date: Mon, 17 Apr 2023 14:59:56 +0200 Subject: [PATCH] fix(moment): handle moment locale when request locale has equal locale part and country part. --- src/Twig/CanonicalizeRuntime.php | 7 +++++++ tests/Twig/CanonicalizeRuntimeTest.php | 1 + 2 files changed, 8 insertions(+) diff --git a/src/Twig/CanonicalizeRuntime.php b/src/Twig/CanonicalizeRuntime.php index 6f4735a7..5cb65e51 100644 --- a/src/Twig/CanonicalizeRuntime.php +++ b/src/Twig/CanonicalizeRuntime.php @@ -52,6 +52,13 @@ public function getCanonicalizedLocaleForMoment(): ?string } } + // Handle locales that has equal langage part and country part. + if (($localeParts = explode('-', strtolower($locale))) && \count($localeParts) > 1) { + if ($localeParts[0] === $localeParts[1]) { + $locale = $localeParts[0]; + } + } + return $locale; } diff --git a/tests/Twig/CanonicalizeRuntimeTest.php b/tests/Twig/CanonicalizeRuntimeTest.php index cdf9cdd7..d01f8c7f 100644 --- a/tests/Twig/CanonicalizeRuntimeTest.php +++ b/tests/Twig/CanonicalizeRuntimeTest.php @@ -103,6 +103,7 @@ public function momentLocalesProvider(): array ['id', 'id'], ['is', 'is'], ['it', 'it'], + ['it', 'it-IT'], ['ja', 'ja'], ['jv', 'jv'], ['ka', 'ka'],