Skip to content

Conversation

@santysisi
Copy link
Contributor

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #62207
License MIT

This fix follows this recommendation

Since this fix adds a new request for a different path, I'm not sure whether to use branch 6.4 or perhaps 8.1. Please let me know.

This fix requires the zip extension because the returned file is a ZIP archive, and this extension is needed to extract the contents. This fix does not add that extension as a dependency; instead, it only uses extension_loaded to check if it is loaded in the project.

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "7.4" but it seems your PR description refers to branch "6.4".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@carsonbot carsonbot added this to the 7.4 milestone Nov 8, 2025
@santysisi santysisi changed the base branch from 7.4 to 6.4 November 8, 2025 22:00
@santysisi santysisi force-pushed the fix/translation-lokalize-project-to-big-for-sync-export branch 3 times, most recently from 439bb53 to fee6f0b Compare November 8, 2025 22:15
@santysisi
Copy link
Contributor Author

santysisi commented Nov 8, 2025

Status: needs work

Its necessary add new tests for the new request.

I tested this solution with a test account and a very simple example.

I will wait for @bastien70's confirmation that it works in his environment before add the new tests.

@santysisi santysisi force-pushed the fix/translation-lokalize-project-to-big-for-sync-export branch 7 times, most recently from e984324 to 8ba777f Compare November 9, 2025 00:18
@bastien70
Copy link

Hello, it works! Congratulations et thank you! :)

@santysisi santysisi force-pushed the fix/translation-lokalize-project-to-big-for-sync-export branch from 8ba777f to 414d6da Compare November 11, 2025 00:41
@santysisi
Copy link
Contributor Author

santysisi commented Nov 11, 2025

Status: needs review

Bastien has already checked this solution in his environment (Thanks Bastien for the check!), and the test has been added.

Edit: I believe the errors are not relevant in the context of the PR

@santysisi santysisi force-pushed the fix/translation-lokalize-project-to-big-for-sync-export branch 2 times, most recently from 604182b to 4f27075 Compare November 11, 2025 11:57
@santysisi santysisi force-pushed the fix/translation-lokalize-project-to-big-for-sync-export branch from 4f27075 to de16442 Compare November 11, 2025 21:38
@santysisi santysisi force-pushed the fix/translation-lokalize-project-to-big-for-sync-export branch 2 times, most recently from f69efc0 to 6b09c0a Compare November 11, 2025 22:13
{
private const LOKALISE_GET_KEYS_LIMIT = 5000;
private const PROJECT_TOO_BIG_STATUS_CODE = 413;
/** @var list<string> */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed

}

if (200 !== $response->getStatusCode()) {
if (($errorCode = $responseContent['error']['code'] ?? null) && self::PROJECT_TOO_BIG_STATUS_CODE === $errorCode) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (($errorCode = $responseContent['error']['code'] ?? null) && self::PROJECT_TOO_BIG_STATUS_CODE === $errorCode) {
if (self::PROJECT_TOO_BIG_STATUS_CODE !== ($responseContent['error']['code'] ?? null)) {
throw ...

break;
}
++$attempt;
usleep(500000 * $attempt);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this retry strategy recommended anywhere? Why not just hit every 500ms without increasing the delay?

usleep(500000 * $attempt);
}

$response = $this->client->request('GET', $downloadUrl, ['buffer' => true]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to buffer since we write by chunk:

Suggested change
$response = $this->client->request('GET', $downloadUrl, ['buffer' => true]);
$response = $this->client->request('GET', $downloadUrl, ['buffer' => false]);

(the alternative would be to pass a file handler instead of a boolean, then wait for the last chunk below, but it's also fine as you wrote it)

if (200 !== $response->getStatusCode()) {
throw new ProviderException(\sprintf('Unable to download translations file from Lokalise: "%s".', $response->getContent(false)), $response);
}
$newfile = \sprintf('%s%s%s.zip', sys_get_temp_dir(), \DIRECTORY_SEPARATOR, uniqid());
Copy link
Member

@nicolas-grekas nicolas-grekas Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$newfile = \sprintf('%s%s%s.zip', sys_get_temp_dir(), \DIRECTORY_SEPARATOR, uniqid());
$zipFile = tempnam(sys_get_temp_dir(), 'lokalise');
$extractPath = $zipFile.'.dir';

fclose($fileHandler);

$zip = new \ZipArchive();
if (!$zip->open($newfile, \ZipArchive::CREATE)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!$zip->open($newfile, \ZipArchive::CREATE)) {
if (!$zip->open($zipFile)) {


$zip = new \ZipArchive();
if (!$zip->open($newfile, \ZipArchive::CREATE)) {
throw new LogicException(\sprintf('failed to open zip file "%s".', $newfile));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same below:

Suggested change
throw new LogicException(\sprintf('failed to open zip file "%s".', $newfile));
throw new LogicException(\sprintf('Failed to open zip file "%s".', $zipFile));

if (\in_array($filename, ['.', '..'])) {
continue;
}
$path = \sprintf('%s%s%s', $dir, \DIRECTORY_SEPARATOR, $filename);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$path = \sprintf('%s%s%s', $dir, \DIRECTORY_SEPARATOR, $filename);
$path = $dir.'/'.$filename;

{
$fileContents = [];
foreach (scandir($dir) as $filename) {
if (\in_array($filename, ['.', '..'])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (\in_array($filename, ['.', '..'])) {
if (\in_array($filename, ['.', '..'], true)) {

}
$path = \sprintf('%s%s%s', $dir, \DIRECTORY_SEPARATOR, $filename);
if (is_dir($path)) {
$fileContents = array_merge($fileContents, $this->getFileContents($path, $filename));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change the implementation of the method and let's not pretend this can handle arbitrary recursive unzipped content
we can do a two levels read of the dir: level 1 = languages, str_replace included, level 2 = content

@santysisi santysisi force-pushed the fix/translation-lokalize-project-to-big-for-sync-export branch from 6b09c0a to 565c8c2 Compare November 12, 2025 11:49
@nicolas-grekas nicolas-grekas modified the milestones: 7.4, 6.4 Nov 12, 2025
@nicolas-grekas nicolas-grekas force-pushed the fix/translation-lokalize-project-to-big-for-sync-export branch from 565c8c2 to a79695c Compare November 12, 2025 18:36
@nicolas-grekas
Copy link
Member

Thank you @santysisi.

@nicolas-grekas nicolas-grekas merged commit 2f41a5a into symfony:6.4 Nov 12, 2025
10 of 11 checks passed
$downloadUrl = $process['details']['download_url'];
break;
}
usleep(500000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t we have some kind of timeout in case the API never responds with any of the codes we use to detect success and failure?

This was referenced Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Translations] Lokalize - "Project too big for sync export. Please use our async export endpoint instead

5 participants