Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): sorting issue when different locales are used on host machines #1808

Merged
merged 5 commits into from
Nov 29, 2023
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/cli/src/api/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,15 @@ function orderByOrigin<T extends ExtractedCatalogType>(messages: T): T {
}

export function orderByMessage<T extends ExtractedCatalogType>(messages: T): T {
// hardcoded en-US locale to have consistent sorting
// @see https://github.com/lingui/js-lingui/pull/1808
const collator = new Intl.Collator("en-US");

return Object.keys(messages)
.sort((a, b) => {
const aMsg = messages[a].message || ""
const bMsg = messages[b].message || ""
return aMsg.localeCompare(bMsg)
return collator.compare(aMsg, bMsg)
})
.reduce((acc, key) => {
;(acc as any)[key] = messages[key]
Expand Down
Loading