Skip to content

Commit

Permalink
Merge pull request #41 from gelbehexe/main
Browse files Browse the repository at this point in the history
Make option "excludedDirectories" also available as configuration opt…
  • Loading branch information
LarsWiegers authored Jul 20, 2023
2 parents cdf3060 + 2a94701 commit 6b29488
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 5 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ Some packages have their own language files, it is probably smart to exclude the
```php
php artisan translations:check --excludedDirectories=lang/vendor
```

This option is also available as configuration option 'excluded_directories'.

For example:
```php
'excluded_directories' => ['lang/vendor'],
```

### Exclude languages
This section provides instructions on how to exclude specific languages from being checked.

Expand Down
19 changes: 16 additions & 3 deletions config/translations-checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,20 @@
|
*/
'exclude_languages' => [],
];



/*
|--------------------------------------------------------------------------
| Excludes Directories
|--------------------------------------------------------------------------
|
| This configuration option allows you to exclude specific directories from
| being processed or checked. The array contains the directory path that
| should be excluded from being scanned. It can be overridden by passing the
| command line option "--excludedDirectories=...". Pass command line option
| "--excludedDirectories=none" to not exclude any directory.
|
| Example: ['lang/vendor']
|
*/
'excluded_directories' => [],
];
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CheckIfTranslationsAreAllThereCommand extends Command
*
* @var string
*/
protected $signature = 'translations:check {--directory=} {--excludedDirectories=none}';
protected $signature = 'translations:check {--directory=} {--excludedDirectories=config}';
/**
* The console command description.
*
Expand Down Expand Up @@ -54,7 +54,9 @@ public function handle()
{
$directory = $this->option('directory') ?: app()->langPath();

if ($this->option('excludedDirectories') === 'none') {
if ($this->option('excludedDirectories') === 'config') {
$this->excludedDirectories = (array)config('translations-checker.excluded_directories', []);
} elseif ($this->option('excludedDirectories') === 'none') {
$this->excludedDirectories = [];
} elseif ($this->option('excludedDirectories')) {
$this->excludedDirectories = explode(',', $this->option('excludedDirectories'));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Tests\Unit\Console\Commands;

use Tests\TestCase;

class CheckIfExcludedDirectoriesConfigurationOptionWorksTest extends TestCase
{
private string $languagesDir = 'tests/resources/lang/excluded_directories';
private string $excludedLanguagesDir = 'excluded';

public function testIfConfigurationOptionWorks()
{
config()->set('translations-checker.excluded_directories', [$this->excludedLanguagesDir]);

$command = $this->artisan('translations:check', [
'--directory' => $this->languagesDir
]);

$command->assertExitCode(0);
}

public function testIfCommandlineOptionOverrulesConfigurationOption()
{
config()->set('translations-checker.excluded_directories', [$this->excludedLanguagesDir]);

$command = $this->artisan('translations:check', [
'--directory' => $this->languagesDir,
'--excludedDirectories' => 'none',
]);

$command->assertExitCode(1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'existing_key2_only_de' => 'Only in de existing Key 2',
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'existing_key2' => 'Existing Key 2 (en)',
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'existing_key1' => 'Existing Key 1 (de)',
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

return [
'existing_key1' => 'Existing Key 1 (en)',
];

0 comments on commit 6b29488

Please sign in to comment.