Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions tests/Language/AbstractTranslationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,61 @@ final public function testAllConfiguredLanguageKeysAreInOrder(string $locale): v
));
}

/**
* @see https://codeigniter4.github.io/CodeIgniter4/outgoing/localization.html#replacing-parameters
*
* @dataProvider localesProvider
*/
final public function testAllLocalizationParametersAreNotTranslated(string $locale): void
{
$diffs = [];

foreach ($this->foundSets($locale) as $file) {
$original = $this->loadFile($file);
$translated = $this->loadFile($file, $locale);

foreach ($original as $key => $translation) {
if (! array_key_exists($key, $translated)) {
continue;
}

preg_match_all('/(\{[^\}]+\})/', $translation, $matches);
array_shift($matches);

if ($matches === []) {
unset($matches);

continue;
}

foreach ($matches as $match) {
foreach ($match as $parameter) {
if (strpos($translated[$key], (string) $parameter) === false) {
$id = sprintf('%s.%s', substr($file, 0, -4), $key);

$diffs[$id] ??= [];

$diffs[$id][] = $parameter;
}
}
}

unset($matches);
}
}

ksort($diffs);

$this->assertEmpty($diffs, sprintf(
"Failed asserting that parameters of translation keys are not translated:\n%s",
implode("\n", array_map(
static fn (string $key, array $values): string => sprintf(' * %s => %s', $key, implode(', ', $values)),
array_keys($diffs),
array_values($diffs)
))
));
}

/**
* @return string[][]
*/
Expand Down