From 9c902a2ca26cb8570beebf591c25d5dbbf7b26d8 Mon Sep 17 00:00:00 2001 From: Julian Prieber <60265788+JulianPrieber@users.noreply.github.com> Date: Wed, 13 Dec 2023 17:10:37 +0100 Subject: [PATCH] Added translation-check command php artisan translation-check {LANG} For example: php artisan translation-check de --- app/Console/Commands/CheckTranslations.php | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 app/Console/Commands/CheckTranslations.php diff --git a/app/Console/Commands/CheckTranslations.php b/app/Console/Commands/CheckTranslations.php new file mode 100644 index 0000000..a2134ff --- /dev/null +++ b/app/Console/Commands/CheckTranslations.php @@ -0,0 +1,44 @@ +argument('language'); + $defaultTranslations = include base_path("resources/lang/{$defaultLanguage}/messages.php"); + $translations = include base_path("resources/lang/{$languageCode}/messages.php"); + + $missingKeys = $this->getMissingKeys($defaultTranslations, $translations); + + if (count($missingKeys) > 0) { + $this->output->error("{$languageCode} translation file is out of date!"); + $this->output->table(['Missing Keys'], $missingKeys); + $this->output->error('Number of missing keys: ' . count($missingKeys)); + } else { + $this->output->success("{$languageCode} translation file is up to date!"); + } + } + + protected function getMissingKeys(array $default, array $translations) + { + $missingKeys = []; + + foreach (Arr::dot($default) as $key => $value) { + if (!Arr::has($translations, $key)) { + $missingKeys[] = [$key]; + } + } + + return $missingKeys; + } +}