Skip to content

Commit bb55683

Browse files
committed
supoport partial translation key
1 parent c7b2567 commit bb55683

File tree

8 files changed

+65
-4
lines changed

8 files changed

+65
-4
lines changed

src/Commands/ShowDeadTranslationsCommand.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,46 @@ public function handle(): int
1818
Translator::clearCache();
1919
}
2020

21+
$results = [
22+
['.blade.php', 0, 0],
23+
['.php', 0, 0],
24+
];
25+
26+
$bar = $this->output->createProgressBar();
27+
2128
$translations = Translator::getAllDeadTranslations(
22-
progress: function (string $file, array $translations) {
23-
$this->line($file);
29+
progress: function (string $file, array $translations) use (&$results, $bar) {
30+
31+
if (str($file)->endsWith('.blade.php')) {
32+
// $this->line($file);
33+
34+
$results[0][2] += 1;
35+
if (count($translations)) {
36+
$results[0][1] += 1;
37+
}
38+
} elseif (str($file)->endsWith('.php')) {
39+
$results[1][2] += 1;
40+
if (count($translations)) {
41+
$results[1][1] += 1;
42+
}
43+
}
44+
45+
$bar->advance();
46+
47+
// $this->output->write("<fg=green>✔️</>");
48+
// $this->output->write(".");
2449
}
2550
);
2651

52+
$bar->finish();
53+
54+
$this->newLine();
55+
56+
$this->table(
57+
headers: ['Type', 'With translations', 'Total'],
58+
rows: $results,
59+
);
60+
2761
$rows = collect($translations)
2862
->flatMap(
2963
fn (array $namespaces, string $locale) => collect($namespaces)

src/Services/SearchCode/PhpParserService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public static function scanCode(string $code): array
8080
return $value instanceof String_ ? $value->value : null;
8181
})
8282
->filter()
83-
->values()
8483
->sort(SORT_NATURAL)
84+
->values()
8585
->toArray();
8686
}
8787

src/Translator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ public function getDeadTranslations(
124124

125125
$usedTranslationsKeys = array_keys($this->getFilesByUsedTranslations($service, $progress));
126126

127-
return $definedTranslationsKeys->filter(fn (string $key) => ! in_array("{$namespace}.{$key}", $usedTranslationsKeys))->toArray();
127+
return $definedTranslationsKeys
128+
->reject(fn (string $key) => str("{$namespace}.{$key}")->startsWith($usedTranslationsKeys))
129+
->values()
130+
->toArray();
128131
}
129132

130133
/**

tests/Feature/TranslatorTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@
3333
'dummy' => [
3434
'class' => 'class factice',
3535
'component' => 'composant factice',
36+
'nested' => [
37+
'used',
38+
'as',
39+
'array',
40+
],
3641
'view' => 'vue factice',
3742
],
3843
'empty' => 'Vide',

tests/Unit/PhpParserServiceTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
'messages.dummy.view',
4040
],
4141
"{$resourcesPath}/views/dummy-view.blade.php" => [
42+
'messages.dummy.nested',
4243
'messages.dummy.view',
4344
'messages.dummy.view',
4445
],
@@ -71,13 +72,20 @@
7172
"{$resourcesPath}/components/dummy-component.blade.php",
7273
],
7374
],
75+
'messages.dummy.nested' => [
76+
'count' => 1,
77+
'files' => [
78+
"{$resourcesPath}/views/dummy-view.blade.php",
79+
],
80+
],
7481
'messages.dummy.view' => [
7582
'count' => 3,
7683
'files' => [
7784
"{$resourcesPath}/components/dummy-component.blade.php",
7885
"{$resourcesPath}/views/dummy-view.blade.php",
7986
],
8087
],
88+
8189
]);
8290
})->skipOnWindows();
8391

tests/src/lang/en/messages.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,10 @@
1212
'class' => 'dummy class',
1313
'component' => 'dummy component',
1414
'view' => 'dummy view',
15+
'nested' => [
16+
'used',
17+
'as',
18+
'array',
19+
],
1520
],
1621
];

tests/src/lang/fr/messages.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,10 @@
1414
'class' => 'class factice',
1515
'component' => 'composant factice',
1616
'view' => 'vue factice',
17+
'nested' => [
18+
'used',
19+
'as',
20+
'array',
21+
],
1722
],
1823
];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<div>
22
{{ __('messages.dummy.view') }}
33
{{ __('messages.dummy.view') }}
4+
{{ __('messages.dummy.nested') }}
45
</div>

0 commit comments

Comments
 (0)