diff --git a/src/Commands/FindMissingTranslations.php b/src/Commands/FindMissingTranslations.php index 95e8133..a8d2519 100644 --- a/src/Commands/FindMissingTranslations.php +++ b/src/Commands/FindMissingTranslations.php @@ -134,16 +134,19 @@ private function compareLanguages(string $baseLanguagePath, array $baseLanguageF * Compare array keys recursively * @param array> $firstArray * @param array> $secondArray + * @param string|null $prefix * @return list */ - private function arrayDiffRecursive(array $firstArray, array $secondArray): array + private function arrayDiffRecursive(array $firstArray, array $secondArray, ?string $prefix = null): array { $outputDiff = []; foreach ($firstArray as $key => $value) { + $fullKey = $prefix !== null ? "{$prefix}.{$key}" : $key; + if (array_key_exists($key, $secondArray)) { if (is_array($value)) { - $recursiveDiff = $this->arrayDiffRecursive($value, $secondArray[$key]); + $recursiveDiff = $this->arrayDiffRecursive($value, $secondArray[$key], $fullKey); if (count($recursiveDiff)) { foreach ($recursiveDiff as $diff) { $outputDiff[] = $diff; @@ -151,7 +154,7 @@ private function arrayDiffRecursive(array $firstArray, array $secondArray): arra } } } else { - $outputDiff[] = $key; + $outputDiff[] = $fullKey; } } diff --git a/tests/Commands/FindMissingTranslationsTest.php b/tests/Commands/FindMissingTranslationsTest.php index 0793177..2c26f47 100644 --- a/tests/Commands/FindMissingTranslationsTest.php +++ b/tests/Commands/FindMissingTranslationsTest.php @@ -33,9 +33,24 @@ public function it_reports_about_missing_translation_keys(): void $output = Artisan::output(); $this->assertSame(1, $exitCode); - $this->assertStringContainsString('| be | a.php | OK |', $output); - $this->assertStringContainsString('| es | a.php | OK |', $output); - $this->assertStringContainsString('| fr | a.php | OK |', $output); + $this->assertStringContainsString('| be | a.php | OK ', $output); + $this->assertStringContainsString('| es | a.php | OK ', $output); + $this->assertStringContainsString('| fr | a.php | OK ', $output); + } + + #[Test] + public function it_reports_about_missing_translation_keys_inside_group(): void + { + $this->withoutMockingConsoleOutput(); + + $dir = __DIR__ . '/unsync_lang_files'; + $exitCode = $this->artisan("translations:missing --dir=$dir --base=en"); + $output = Artisan::output(); + + $this->assertSame(1, $exitCode); + $this->assertStringContainsString('| be | a.php | group.Help ', $output); + $this->assertStringContainsString('| es | a.php | group.Help ', $output); + $this->assertStringContainsString('| fr | a.php | group.Help ', $output); } #[Test] @@ -48,9 +63,9 @@ public function it_reports_about_missing_translation_keys_only_lang(): void $output = Artisan::output(); $this->assertSame(1, $exitCode); - $this->assertStringContainsString('| be | a.php | OK |', $output); - $this->assertStringContainsString('| es | a.php | OK |', $output); - $this->assertStringNotContainsString('| fr | a.php | OK |', $output); + $this->assertStringContainsString('| be | a.php | OK ', $output); + $this->assertStringContainsString('| es | a.php | OK ', $output); + $this->assertStringNotContainsString('| fr | a.php | OK ', $output); } #[Test] @@ -63,8 +78,8 @@ public function it_reports_about_missing_translation_keys_exclude_lang(): void $output = Artisan::output(); $this->assertSame(1, $exitCode); - $this->assertStringNotContainsString('| be | a.php | OK |', $output); - $this->assertStringContainsString('| es | a.php | OK |', $output); - $this->assertStringNotContainsString('| fr | a.php | OK |', $output); + $this->assertStringNotContainsString('| be | a.php | OK ', $output); + $this->assertStringContainsString('| es | a.php | OK ', $output); + $this->assertStringNotContainsString('| fr | a.php | OK ', $output); } } diff --git a/tests/Commands/unsync_lang_files/be/a.php b/tests/Commands/unsync_lang_files/be/a.php index 4933306..23de21b 100644 --- a/tests/Commands/unsync_lang_files/be/a.php +++ b/tests/Commands/unsync_lang_files/be/a.php @@ -5,5 +5,7 @@ 'No' => 'Не', // 'OK' => 'OK', missing key - // 'group' => [], // missing group + 'group' => [ + // missing group key + ], ]; diff --git a/tests/Commands/unsync_lang_files/en/a.php b/tests/Commands/unsync_lang_files/en/a.php index 0fe0e51..94e4cf5 100644 --- a/tests/Commands/unsync_lang_files/en/a.php +++ b/tests/Commands/unsync_lang_files/en/a.php @@ -4,4 +4,8 @@ 'Yes' => 'Yes', 'No' => 'No', 'OK' => 'OK', + + 'group' => [ + 'Help' => 'Help', + ], ]; diff --git a/tests/Commands/unsync_lang_files/es/a.php b/tests/Commands/unsync_lang_files/es/a.php index 4cd63b2..7a3f793 100644 --- a/tests/Commands/unsync_lang_files/es/a.php +++ b/tests/Commands/unsync_lang_files/es/a.php @@ -5,5 +5,7 @@ 'No' => 'No', // 'OK' => 'OK', missing key - // 'group' => [], // missing group + 'group' => [ + // missing group key + ], ]; diff --git a/tests/Commands/unsync_lang_files/fr/a.php b/tests/Commands/unsync_lang_files/fr/a.php index 57fe343..9906224 100644 --- a/tests/Commands/unsync_lang_files/fr/a.php +++ b/tests/Commands/unsync_lang_files/fr/a.php @@ -6,5 +6,7 @@ 'No' => 'Non', // 'OK' => 'OK', missing key - // 'group' => [], // missing group + 'group' => [ + // missing group key + ], ];