Skip to content

Commit

Permalink
Merge pull request #14 from nextapps-be/respect-excluded-files-config…
Browse files Browse the repository at this point in the history
…-when-downloading

Do not delete excluded translation files when downloading poeditor translations
  • Loading branch information
gdebrauwer authored Jan 19, 2024
2 parents 00d91d1 + 9b0edf0 commit 84c66fc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// Converts implicit variables into explicit ones in double-quoted strings or heredoc syntax.
'explicit_string_variable' => true,
// Transforms imported FQCN parameters and return types in function arguments to short version.
'fully_qualified_strict_types' => true,
'fully_qualified_strict_types' => false,
// Add missing space between function's argument and its typehint.
'function_typehint_space' => true,
// Pre- or post-increment and decrement operators should be used if possible.
Expand Down
8 changes: 7 additions & 1 deletion src/Translations/TranslationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,13 @@ protected function createEmptyLocaleFolder(string $locale)
$path = $this->getLangPath($locale);

if (file_exists($path)) {
$this->filesystem->deleteDirectory($path);
foreach ($this->filesystem->allFiles($path) as $file) {
if (! in_array($file->getFilename(), config('poeditor-sync.excluded_files', []))) {
$this->filesystem->delete($file->getRealPath());
}
}

return;
}

$this->filesystem->makeDirectory($path);
Expand Down
21 changes: 21 additions & 0 deletions tests/DownloadCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,27 @@ public function it_removes_old_php_translations_of_locale()
$this->assertTrue(file_exists($this->getLangPath('en/new-php-file.php')));
}

/** @test */
public function it_does_not_remove_php_translations_of_locale_if_php_translation_is_excluded_in_config()
{
file_put_contents($this->getLangPath('en/excluded-php-file.php'), ['foo' => 'bar']);
file_put_contents($this->getLangPath('en/not-excluded-php-file.php'), ['foo' => 'bar']);

config()->set('poeditor-sync.excluded_files', ['excluded-php-file.php']);

$this->mockPoeditorDownload('en', [
'some-php-file' => [
'foo' => 'bar',
],
]);

$this->artisan('poeditor:download')->assertExitCode(0);

$this->assertTrue(file_exists($this->getLangPath('en/excluded-php-file.php')));
$this->assertFalse(file_exists($this->getLangPath('en/not-excluded-php-file.php')));
$this->assertTrue(file_exists($this->getLangPath('en/some-php-file.php')));
}

/** @test */
public function it_overrides_old_json_translation_of_locale()
{
Expand Down

0 comments on commit 84c66fc

Please sign in to comment.