Skip to content

Commit

Permalink
fix(moment): handle moment locale when request locale has equal local…
Browse files Browse the repository at this point in the history
…e part and country part.
  • Loading branch information
jgtrescazes committed Apr 17, 2023
1 parent d71ee63 commit e08d522
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Twig/CanonicalizeRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions tests/Twig/CanonicalizeRuntimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public function momentLocalesProvider(): array
['id', 'id'],
['is', 'is'],
['it', 'it'],
['it', 'it-IT'],
['ja', 'ja'],
['jv', 'jv'],
['ka', 'ka'],
Expand Down

0 comments on commit e08d522

Please sign in to comment.