-
Notifications
You must be signed in to change notification settings - Fork 5
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
run cleanup command after upload and ask to cleanup terms in poeditor #24
Conversation
src/Commands/UploadCommand.php
Outdated
$diff = collect(app(Poeditor::class)->download($this->getPoeditorLocale()))->dot() | ||
->diff(collect($translations)->dot()); | ||
|
||
if ($diff->isEmpty()) { | ||
$this->info('The translations match the ones on POEditor'); | ||
} else { | ||
$this->error('The following translations do not match the ones on POEditor:'); | ||
|
||
$this->table(['Key', 'Value'], $diff->map(function ($value, $key) { | ||
return [$key, $value]; | ||
})); | ||
|
||
if ($this->ask('Do you want to clean up the translations on POEditor? (y/n)')) { | ||
$response = app(Poeditor::class)->upload($this->getPoeditorLocale(), $translations, true, true); | ||
|
||
$this->info("Deleted {$response->getDeletedTermsCount()} terms"); | ||
} | ||
} |
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.
$diff = collect(app(Poeditor::class)->download($this->getPoeditorLocale()))->dot() | |
->diff(collect($translations)->dot()); | |
if ($diff->isEmpty()) { | |
$this->info('The translations match the ones on POEditor'); | |
} else { | |
$this->error('The following translations do not match the ones on POEditor:'); | |
$this->table(['Key', 'Value'], $diff->map(function ($value, $key) { | |
return [$key, $value]; | |
})); | |
if ($this->ask('Do you want to clean up the translations on POEditor? (y/n)')) { | |
$response = app(Poeditor::class)->upload($this->getPoeditorLocale(), $translations, true, true); | |
$this->info("Deleted {$response->getDeletedTermsCount()} terms"); | |
} | |
} | |
collect(app(Poeditor::class)->download($this->getPoeditorLocale())) | |
->dot() | |
->keys() | |
->diff(collect($translations)->dot()->keys()) | |
->whenNotEmpty(function ($locallyDeletedTranslationsKeys) use ($translations) { | |
$this->error('The following translation keys do not exist locally but do exist in POEditor:'); | |
$this->table( | |
['Translation Key'], | |
$locallyDeletedTranslationsKeys->map(fn ($key) => [$key])->all() | |
); | |
if (! $this->confirm('Do you want to delete those translation keys in POEditor? (y/n)')) { | |
return; | |
} | |
$response = app(Poeditor::class)->upload($this->getPoeditorLocale(), $translations, true, true); | |
$this->info("Deleted {$response->getDeletedTermsCount()} terms"); | |
}); |
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.
@yinx Maybe we can make it even simpler.
Now we first upload, then download and compare the download with local, and finally we upload to delete terms
But what if we first download, then compare the download with local, and then upload with correct "sync" parameter 🤔 Then only one upload as necessary and only upload response needs to be shown
tests/UploadCommandTest.php
Outdated
$this->artisan('poeditor:upload --force') | ||
->assertExitCode(0); | ||
} | ||
|
||
/** @test */ | ||
public function it_asks_for_confirmation_when_translations_do_not_match_with_cleanup_enabled() |
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.
public function it_asks_for_confirmation_when_translations_do_not_match_with_cleanup_enabled() | |
public function it_asks_for_confirmation_when_local_translations_keys_do_not_match_translations_keys_in_poeditor() |
tests/UploadCommandTest.php
Outdated
$this->artisan('poeditor:upload nl_BE')->assertExitCode(0); | ||
} | ||
|
||
/** @test */ | ||
public function it_checks_the_local_translation_keys_with_the_downloaded_keys() |
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.
is this not covered by all the other tests 🤔
tests/UploadCommandTest.php
Outdated
['php-file.baz', 'bar'], | ||
] | ||
) | ||
->expectsOutput('Deleted ' . 1 . ' terms') |
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.
->expectsOutput('Deleted ' . 1 . ' terms') | |
->expectsOutput("{$response->getDeletedTermsCount()} terms deleted") |
tests/UploadCommandTest.php
Outdated
], true, true, new UploadResponse([ | ||
'result' => [ | ||
'terms' => ['added' => $this->faker->randomNumber(), 'deleted' => 1], | ||
'translations' => ['added' => $this->faker->randomNumber(), 'updated' => $this->faker->randomNumber()], | ||
], | ||
])); |
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.
], true, true, new UploadResponse([ | |
'result' => [ | |
'terms' => ['added' => $this->faker->randomNumber(), 'deleted' => 1], | |
'translations' => ['added' => $this->faker->randomNumber(), 'updated' => $this->faker->randomNumber()], | |
], | |
])); | |
], true, true, $response = $this->getPoeditorUploadResponse()); |
1a2a473
to
decc228
Compare
f241b56
to
24c28ac
Compare
src/Commands/UploadCommand.php
Outdated
$cleanup = false; | ||
|
||
collect(app(Poeditor::class)->download($this->getPoeditorLocale())) | ||
->dot() | ||
->keys() | ||
->diff(collect($translations)->dot()->keys()) | ||
->whenNotEmpty(function ($locallyDeletedTranslationsKeys) use (&$cleanup) { | ||
$this->error('The following translation keys do not exist locally but do exist in POEditor:'); | ||
|
||
$this->table( | ||
['Translation Key'], | ||
$locallyDeletedTranslationsKeys->map(fn ($key) => [$key])->all() | ||
); | ||
|
||
if ($this->confirm('Do you want to delete those translation keys in POEditor? (y/n)')) { | ||
$cleanup = true; | ||
} | ||
}); |
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.
$cleanup = false; | |
collect(app(Poeditor::class)->download($this->getPoeditorLocale())) | |
->dot() | |
->keys() | |
->diff(collect($translations)->dot()->keys()) | |
->whenNotEmpty(function ($locallyDeletedTranslationsKeys) use (&$cleanup) { | |
$this->error('The following translation keys do not exist locally but do exist in POEditor:'); | |
$this->table( | |
['Translation Key'], | |
$locallyDeletedTranslationsKeys->map(fn ($key) => [$key])->all() | |
); | |
if ($this->confirm('Do you want to delete those translation keys in POEditor? (y/n)')) { | |
$cleanup = true; | |
} | |
}); | |
$cleanup = collect(app(Poeditor::class)->download($this->getPoeditorLocale())) | |
->dot() | |
->keys() | |
->diff(collect($translations)->dot()->keys()) | |
->whenNotEmpty(function ($locallyDeletedTranslationsKeys) use (&$cleanup) { | |
$this->error('The following translation keys do not exist locally but do exist in POEditor:'); | |
$this->table( | |
['Translation Key'], | |
$locallyDeletedTranslationsKeys->map(fn ($key) => [$key])->all() | |
); | |
return $this->confirm('Do you want to delete those translation keys in POEditor? (y/n)'); | |
}, fn () => false); |
tests/UploadCommandTest.php
Outdated
$this->mockPoeditorUpload('en', [ | ||
'php-file' => [ | ||
'bar' => 'foo', | ||
], | ||
]); | ||
|
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.
$this->mockPoeditorUpload('en', [ | |
'php-file' => [ | |
'bar' => 'foo', | |
], | |
]); |
can be removed as this upload is never executed
No description provided.