Skip to content

Commit

Permalink
fix(moment): handle moment locale when request locale has equal langu…
Browse files Browse the repository at this point in the history
…age part and country part.
  • Loading branch information
jgtrescazes authored and jordisala1991 committed Apr 29, 2023
1 parent f75221a commit 12c89f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Twig/CanonicalizeRuntime.php
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions tests/Twig/CanonicalizeRuntimeTest.php
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 12c89f0

Please sign in to comment.