-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Translation] Allow translation:extract
to sort messages with --force
#52938
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
Changes from all commits
ad69499
b2de1a1
f7b5715
e540efe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,8 +23,9 @@ class JsonFileDumper extends FileDumper | |
public function formatCatalogue(MessageCatalogue $messages, string $domain, array $options = []): string | ||
{ | ||
$flags = $options['json_encoding'] ?? \JSON_PRETTY_PRINT; | ||
$sort = $options['sort'] ?? null; | ||
|
||
return json_encode($messages->all($domain), $flags); | ||
return json_encode($messages->all($domain, $sort), $flags); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know what to do with the Psalm errors on this line. They are not related to my PR so I would say that I should not change anything here. What do you say? |
||
} | ||
|
||
protected function getExtension(): string | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,26 +55,44 @@ public function getDomains(): array | |
return array_values($domains); | ||
} | ||
|
||
public function all(string $domain = null): array | ||
public function all(string $domain = null, ?string $sort = null): array | ||
{ | ||
$sort = $sort ? strtolower($sort) : null; | ||
|
||
if (null !== $domain) { | ||
// skip messages merge if intl-icu requested explicitly | ||
if (str_ends_with($domain, self::INTL_DOMAIN_SUFFIX)) { | ||
return $this->messages[$domain] ?? []; | ||
$messages = $this->messages[$domain] ?? []; | ||
} else { | ||
$messages = ($this->messages[$domain.self::INTL_DOMAIN_SUFFIX] ?? []) + ($this->messages[$domain] ?? []); | ||
} | ||
|
||
if ('desc' === $sort) { | ||
krsort($messages); | ||
} elseif ('asc' === $sort) { | ||
ksort($messages); | ||
} | ||
|
||
return ($this->messages[$domain.self::INTL_DOMAIN_SUFFIX] ?? []) + ($this->messages[$domain] ?? []); | ||
return $messages; | ||
} | ||
|
||
$allMessages = []; | ||
|
||
foreach ($this->messages as $domain => $messages) { | ||
if (str_ends_with($domain, self::INTL_DOMAIN_SUFFIX)) { | ||
$domain = substr($domain, 0, -\strlen(self::INTL_DOMAIN_SUFFIX)); | ||
$allMessages[$domain] = $messages + ($allMessages[$domain] ?? []); | ||
$messages = $messages + ($allMessages[$domain] ?? []); | ||
} else { | ||
$allMessages[$domain] = ($allMessages[$domain] ?? []) + $messages; | ||
$messages = ($allMessages[$domain] ?? []) + $messages; | ||
} | ||
|
||
if ('desc' === $sort) { | ||
krsort($messages); | ||
} elseif ('asc' === $sort) { | ||
ksort($messages); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the method throw an error if the value of sort is invalid? I like not being too strict and doing nothing when the value is different, but it's less clear if a typo is made (e.g. passing the value |
||
|
||
$allMessages[$domain] = $messages; | ||
} | ||
|
||
return $allMessages; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit unsure about removing the default value. As explained in my commit, it's to allow "null" value in order to keep the behaviour from before when using
--force
. I made sure to default to "asc" when using--dump-messages
, but I may miss some issues.