*/ function translationLines(string $locale, string $file): array { $lines = require langPath("{$locale}/{$file}"); $flat = []; $flatten = function (array $values, string $prefix) use (&$flatten, &$flat): void { foreach ($values as $key => $value) { is_array($value) ? $flatten($value, $prefix.$key.'.') : $flat[$prefix.$key] = (string) $value; } }; $flatten($lines, ''); return $flat; } /** * @return list */ function placeholdersOf(string $text): array { // A placeholder starts a word: "ALV:n" (Finnish case ending) is not one. preg_match_all('/(? $finnish * @param array $english */ function expectSameTexts(array $finnish, array $english, string $file): void { expect(array_keys($english))->toEqualCanonicalizing(array_keys($finnish)); foreach ($finnish as $key => $text) { expect(placeholdersOf($english[$key]))->toBe(placeholdersOf($text), "Placeholders differ in {$file}: {$key}"); } } dataset('translation files', fn () => array_map('basename', glob(langPath('fi/*.php')))); it('has every Finnish text in English with the same placeholders', function (string $file) { expect(file_exists(langPath("en/{$file}")))->toBeTrue("lang/en/{$file} is missing"); expectSameTexts(translationLines('fi', $file), translationLines('en', $file), $file); })->with('translation files'); it('has no English translation file without a Finnish one', function () { $finnish = array_map('basename', glob(langPath('fi/*.php'))); $english = array_map('basename', glob(langPath('en/*.php'))); expect($english)->toEqualCanonicalizing($finnish); }); it('has the same JSON texts in Finnish and English', function () { $finnish = json_decode((string) file_get_contents(langPath('fi.json')), true, flags: JSON_THROW_ON_ERROR); $english = json_decode((string) file_get_contents(langPath('en.json')), true, flags: JSON_THROW_ON_ERROR); expectSameTexts($finnish, $english, 'fi.json / en.json'); });