diff --git a/src/Console/Commands/CheckIfTranslationsAreAllThereCommand.php b/src/Console/Commands/CheckIfTranslationsAreAllThereCommand.php index cd4d96b..5f924ee 100644 --- a/src/Console/Commands/CheckIfTranslationsAreAllThereCommand.php +++ b/src/Console/Commands/CheckIfTranslationsAreAllThereCommand.php @@ -6,6 +6,7 @@ use Illuminate\Support\Facades\File as FileFacade; use Larswiegers\LaravelTranslationsChecker\Console\Domain\Features\DirectoryExclusion; use Larswiegers\LaravelTranslationsChecker\Console\Domain\Features\GetLanguages; +use Larswiegers\LaravelTranslationsChecker\Console\Domain\Features\KeyExclusion; use Larswiegers\LaravelTranslationsChecker\Console\Domain\Features\LanguagesWithMissingFiles; use Larswiegers\LaravelTranslationsChecker\Console\Domain\Features\LanguagesWithMissingKeys; use Larswiegers\LaravelTranslationsChecker\Console\Domain\File; @@ -20,7 +21,7 @@ class CheckIfTranslationsAreAllThereCommand extends Command * * @var string */ - protected $signature = 'translations:check {--directory=} {--excludedDirectories=config}'; + protected $signature = 'translations:check {--directory=} {--excludedDirectories=config} {--excludedKeys=config}'; /** * The console command description. @@ -66,6 +67,7 @@ public function handle(): int } DirectoryExclusion::getExcludedDirectories($this->options()); + KeyExclusion::getExcludedKeys($this->options()); $languages = $this->getLanguages->getLanguages($topDirectory); diff --git a/src/Console/Domain/Features/KeyExclusion.php b/src/Console/Domain/Features/KeyExclusion.php new file mode 100644 index 0000000..32a7fea --- /dev/null +++ b/src/Console/Domain/Features/KeyExclusion.php @@ -0,0 +1,35 @@ +getKey(), self::$excludedKeys); + } + + /** + * @param array $options + */ + public static function getExcludedKeys(array $options): void + { + if ($options['excludedKeys'] === 'config') { + self::$excludedKeys = (array) config('translations-checker.excluded_keys', []); + } elseif ($options['excludedKeys']) { + self::$excludedKeys = explode(',', $options['excludedKeys']); + } elseif (empty((array) config('translations-checker.excluded_keys', []))) { + self::$excludedKeys = (array) config('translations-checker.excluded_keys', []); + } else { + self::$excludedKeys = []; + } + } +} diff --git a/src/Console/Domain/Features/LanguagesWithMissingKeys.php b/src/Console/Domain/Features/LanguagesWithMissingKeys.php index aed6efe..f4df68e 100644 --- a/src/Console/Domain/Features/LanguagesWithMissingKeys.php +++ b/src/Console/Domain/Features/LanguagesWithMissingKeys.php @@ -50,6 +50,10 @@ public function getMissingKeysTexts(array $realLines, array $languages): void continue; } + if(KeyExclusion::shouldExclude($line)) { + continue; + } + $file = new File($fileKey); $fileName = $file->withoutExtensionAndLanguages($languages); diff --git a/tests/Tests/Unit/Console/Commands/CheckExcludeKeysTest.php b/tests/Tests/Unit/Console/Commands/CheckExcludeKeysTest.php new file mode 100644 index 0000000..249bfa6 --- /dev/null +++ b/tests/Tests/Unit/Console/Commands/CheckExcludeKeysTest.php @@ -0,0 +1,38 @@ +artisan('translations:check', [ + '--directory' => $this->exclusionDir .'/excluded_but_existing', + '--excludedKeys' => 'test.existing_key', + ]); + + $command->assertExitCode(0); + } + + public function testItWorksFineIfKeyIsMissingButIsExcluded() + { + config()->set('translations-checker.excluded_keys', null); + + + $command = $this->artisan('translations:check', [ + '--directory' => $this->exclusionDir .'/excluded_but_missing', + '--excludedKeys' => 'existing_key', + ]); + + $command->assertExitCode(0); + } +} diff --git a/tests/resources/lang/excluded_keys/excluded_but_existing/de/test.php b/tests/resources/lang/excluded_keys/excluded_but_existing/de/test.php new file mode 100644 index 0000000..84a70bb --- /dev/null +++ b/tests/resources/lang/excluded_keys/excluded_but_existing/de/test.php @@ -0,0 +1,5 @@ + 'existing_key', +]; diff --git a/tests/resources/lang/excluded_keys/excluded_but_existing/en/test.php b/tests/resources/lang/excluded_keys/excluded_but_existing/en/test.php new file mode 100644 index 0000000..84a70bb --- /dev/null +++ b/tests/resources/lang/excluded_keys/excluded_but_existing/en/test.php @@ -0,0 +1,5 @@ + 'existing_key', +]; diff --git a/tests/resources/lang/excluded_keys/excluded_but_missing/de/test.php b/tests/resources/lang/excluded_keys/excluded_but_missing/de/test.php new file mode 100644 index 0000000..84a70bb --- /dev/null +++ b/tests/resources/lang/excluded_keys/excluded_but_missing/de/test.php @@ -0,0 +1,5 @@ + 'existing_key', +]; diff --git a/tests/resources/lang/excluded_keys/excluded_but_missing/en/test.php b/tests/resources/lang/excluded_keys/excluded_but_missing/en/test.php new file mode 100644 index 0000000..b625128 --- /dev/null +++ b/tests/resources/lang/excluded_keys/excluded_but_missing/en/test.php @@ -0,0 +1,4 @@ +