diff --git a/src/Twig/CanonicalizeRuntime.php b/src/Twig/CanonicalizeRuntime.php index 6f4735a7..00595fd2 100644 --- a/src/Twig/CanonicalizeRuntime.php +++ b/src/Twig/CanonicalizeRuntime.php @@ -52,6 +52,14 @@ public function getCanonicalizedLocaleForMoment(): ?string } } + // Handle locales that has equal langage part and country part. + if (str_contains($locale, '-')) { + $localeParts = explode('-', strtolower($locale)); + 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'],