File tree Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Expand file tree Collapse file tree 2 files changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -124,6 +124,27 @@ public function getDeadTranslations(
124
124
return $ definedTranslationsKeys ->filter (fn (string $ key ) => ! in_array ("{$ namespace }. {$ key }" , $ usedTranslationsKeys ))->toArray ();
125
125
}
126
126
127
+ /**
128
+ * @return array<string, array<string, string[]>>
129
+ */
130
+ public function getAllDeadTranslations (): array
131
+ {
132
+ return collect ($ this ->getLocales ())
133
+ ->mapWithKeys (function (string $ locale ) {
134
+ $ namespaces = collect ($ this ->getNamespaces ($ locale ));
135
+
136
+ return [
137
+ $ locale => $ namespaces
138
+ ->mapWithKeys (fn (string $ namespace ) => [
139
+ $ namespace => $ this ->getDeadTranslations ($ locale , $ namespace ),
140
+ ])
141
+ ->filter (),
142
+ ];
143
+ })
144
+ ->filter ()
145
+ ->toArray ();
146
+ }
147
+
127
148
/**
128
149
* @param array<string|int, string|int|float|array|null> $values
129
150
*/
Original file line number Diff line number Diff line change 85
85
]);
86
86
});
87
87
88
- it ('finds dead translations ' , function () {
88
+ it ('finds dead translations in a namespace ' , function () {
89
89
$ translator = new Translator (
90
90
storage: $ this ->getStorage (),
91
91
searchcodeService: new PhpParserService ([
110
110
]);
111
111
});
112
112
113
+ it ('finds all dead translations ' , function () {
114
+ $ translator = new Translator (
115
+ storage: $ this ->getStorage (),
116
+ searchcodeService: new PhpParserService ([
117
+ $ this ->getAppPath (),
118
+ $ this ->getResourcesPath (),
119
+ ])
120
+ );
121
+
122
+ $ deadTranslations = $ translator ->getAllDeadTranslations ();
123
+
124
+ expect ($ deadTranslations )->toBe ([
125
+ 'en ' => [
126
+ 'messages ' => [
127
+ 'hello ' ,
128
+ 'add ' ,
129
+ 'home.title ' ,
130
+ 'home.end ' ,
131
+ 'empty ' ,
132
+ ],
133
+ ],
134
+ 'fr ' => [
135
+ 'messages ' => [
136
+ 'hello ' ,
137
+ 'add ' ,
138
+ 'home.title ' ,
139
+ 'home.end ' ,
140
+ 'home.missing ' ,
141
+ 'empty ' ,
142
+ 'missing ' ,
143
+ ],
144
+ ],
145
+ ]);
146
+ });
147
+
113
148
it ('sets translations ' , function () {
114
149
$ translator = new Translator (
115
150
storage: $ this ->getStorage (),
You can’t perform that action at this time.
0 commit comments