[Translation] Make CrowdinProvider::write() add the locales missing from the project - #66028
Conversation
400390c to
56cc42b
Compare
|
Rebased on 8.2 and amended before merge. The locale to language id conversion was Unsupported locales are now left out of the patch instead of travelling with the others, so a single unknown locale no longer stops every other one from being added; they keep falling back to the A 5xx on either request now throws like the rest of the bridge, while a 403 still only logs and skips. Added an I left out an RFC 6902 |
|
Thank you for the rebase and the amend, and above all for catching the language id mapping. I had assumed On the current red, Psalm fails on the new
foreach ($response->toArray()['data'] as $language) {
$id = (string) $language['data']['id'];
$languageIds[str_replace('-', '_', (string) $language['data']['locale'])] ??= $id;
$languageIds[str_replace('-', '_', $id)] = $id;
}Want me to push that, or would you rather fold it into your amend? The two unit test reds look unrelated: the same |
56cc42b to
1caeba4
Compare
…rom the project Loco, Lokalise and Phrase create the locales a project does not have yet, while Crowdin logged them as ignored and skipped them. The project is now patched with the languages it is missing before the upload. Crowdin spells its language IDs its own way, so the list of the languages it supports is fetched to turn a locale into an ID: "fr_FR" is the "fr" language and "es_ES" is the "es-ES" one. A locale Crowdin does not know is left out of the patch, so the other ones are still added, and it keeps falling back to the warning write() already logged. Editing a project needs a token with a read and write "project.settings" scope, so a failure is logged and those locales are skipped as they were before, rather than throwing. A server error still throws, like the rest of the bridge.
1caeba4 to
3db1be0
Compare
|
Thanks, and you are right on both counts. The Psalm error is mine, so I folded the casts into the amend rather than have you push a fix for it: Rebased on 8.2 as well, so the |
|
Thank you @Amoifr. |
|
The rebase cleared both unit test reds as expected. Two things left here. Psalm still reports the same two errors on
|
|
I don't care about psalm if it doesn't spot bugs - so unless those reports are about bugs, it's fine not pursuing the goal of making SA tools happy for the sake of it. |
This covers the Crowdin
write()item of the checklist in #64155. Loco, Lokalise and Phrase create the locales a project is missing, Crowdin loggedIgnored "%s" locale because it is not configured or mapped in the project.and skipped them.write()now adds the target languages the project does not have yet, in onePATCHon the project before the upload, keeping the languages already configured:[{"op": "replace", "path": "/targetLanguageIds", "value": ["fr", "de"]}]The locale is spelled as a Crowdin language ID, with a dash where Symfony uses an underscore, which is the reverse of what
getLanguageIds()already does when reading them. A locale that the project maps under another name is left alone, since it is already known.Editing a project requires a token with a read and write
project.settingsscope, which is the concern raised in the issue. A narrower token cannot add anything, so the failure is logged andwrite()then skips those locales exactly as it does today: no exception, and the locales that do exist are still pushed.Tests cover both paths, the project being patched with the union of its languages, and the
403case where the locales are skipped and the source file is still written. Checked with mocked responses only, not against a live Crowdin project.