@@ -304,6 +304,57 @@ final public function testAllConfiguredLanguageKeysAreInOrder(string $locale): v
304
304
));
305
305
}
306
306
307
+ /**
308
+ * @see https://codeigniter4.github.io/CodeIgniter4/outgoing/localization.html#replacing-parameters
309
+ *
310
+ * @dataProvider localesProvider
311
+ */
312
+ final public function testAllLocalizationParametersAreNotTranslated (string $ locale ): void
313
+ {
314
+ $ diffs = [];
315
+
316
+ foreach ($ this ->foundSets ($ locale ) as $ file ) {
317
+ $ original = $ this ->loadFile ($ file );
318
+ $ translated = $ this ->loadFile ($ file , $ locale );
319
+
320
+ foreach ($ original as $ key => $ translation ) {
321
+ if (! array_key_exists ($ key , $ translated )) {
322
+ continue ;
323
+ }
324
+
325
+ preg_match_all ('/(\{[^\}]+\})/ ' , $ translation , $ matches );
326
+ array_shift ($ matches );
327
+
328
+ if ($ matches === []) {
329
+ unset($ matches );
330
+
331
+ continue ;
332
+ }
333
+
334
+ foreach ($ matches as $ match ) {
335
+ foreach ($ match as $ parameter ) {
336
+ if (strpos ($ translated [$ key ], $ parameter ) === false ) {
337
+ $ diffs [sprintf ('%s.%s ' , substr ($ file , 0 , -4 ), $ key )] = $ parameter ;
338
+ }
339
+ }
340
+ }
341
+
342
+ unset($ matches );
343
+ }
344
+ }
345
+
346
+ ksort ($ diffs );
347
+
348
+ $ this ->assertEmpty ($ diffs , sprintf (
349
+ "Failed asserting that parameters of translation keys are not translated: \n%s " ,
350
+ implode ("\n" , array_map (
351
+ static fn (string $ key , string $ value ): string => sprintf (' * %s => %s ' , $ key , $ value ),
352
+ array_keys ($ diffs ),
353
+ array_values ($ diffs )
354
+ ))
355
+ ));
356
+ }
357
+
307
358
/**
308
359
* @return string[][]
309
360
*/
0 commit comments