@@ -304,6 +304,61 @@ 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 ], (string ) $ parameter ) === false ) {
337
+ $ id = sprintf ('%s.%s ' , substr ($ file , 0 , -4 ), $ key );
338
+
339
+ $ diffs [$ id ] ??= [];
340
+
341
+ $ diffs [$ id ][] = $ parameter ;
342
+ }
343
+ }
344
+ }
345
+
346
+ unset($ matches );
347
+ }
348
+ }
349
+
350
+ ksort ($ diffs );
351
+
352
+ $ this ->assertEmpty ($ diffs , sprintf (
353
+ "Failed asserting that parameters of translation keys are not translated: \n%s " ,
354
+ implode ("\n" , array_map (
355
+ static fn (string $ key , array $ values ): string => sprintf (' * %s => %s ' , $ key , implode (', ' , $ values )),
356
+ array_keys ($ diffs ),
357
+ array_values ($ diffs )
358
+ ))
359
+ ));
360
+ }
361
+
307
362
/**
308
363
* @return string[][]
309
364
*/
0 commit comments