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(
124124 return $ definedTranslationsKeys ->filter (fn (string $ key ) => ! in_array ("{$ namespace }. {$ key }" , $ usedTranslationsKeys ))->toArray ();
125125 }
126126
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+
127148 /**
128149 * @param array<string|int, string|int|float|array|null> $values
129150 */
Original file line number Diff line number Diff line change 8585 ]);
8686});
8787
88- it ('finds dead translations ' , function () {
88+ it ('finds dead translations in a namespace ' , function () {
8989 $ translator = new Translator (
9090 storage: $ this ->getStorage (),
9191 searchcodeService: new PhpParserService ([
110110 ]);
111111});
112112
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+
113148it ('sets translations ' , function () {
114149 $ translator = new Translator (
115150 storage: $ this ->getStorage (),
You can’t perform that action at this time.
0 commit comments