* neue-texte.json: {"Deutscher Text": "Übersetzung", …} (wie strings.json). Vorhandene Schlüssel werden überschrieben. */ if ($argc < 4) { fwrite(STDERR, "Aufruf: php tools/lang_pack_add.php \n"); exit(1); } [$_, $old, $newJson, $out] = $argv; $add = json_decode((string) file_get_contents($newJson), true); if (!is_array($add)) { fwrite(STDERR, "Die Datei mit den neuen Texten ist kein gültiges JSON.\n"); exit(1); } $zip = new ZipArchive(); if ($zip->open($old) !== true) { fwrite(STDERR, "Das alte ZIP lässt sich nicht öffnen.\n"); exit(1); } $files = []; for ($i = 0; $i < $zip->numFiles; $i++) $files[str_replace(chr(92), '/', $zip->getNameIndex($i))] = $zip->getFromIndex($i); $zip->close(); $strKey = $manKey = null; foreach ($files as $name => $_c) { if (str_ends_with($name, '/strings.json')) $strKey = $name; if (str_ends_with($name, '/plugin.json')) $manKey = $name; } if (!$strKey || !$manKey) { fwrite(STDERR, "strings.json oder plugin.json fehlt im ZIP.\n"); exit(1); } $dict = json_decode($files[$strKey], true); $info = ['_info' => $dict['_info'] ?? '']; unset($dict['_info']); foreach ($add as $k => $v) { if (!is_string($k) || !is_string($v) || $k === '' || $k !== trim($k) && false) continue; if (substr_count($k, '{') !== substr_count($v, '{')) { fwrite(STDERR, "Platzhalter ungleich: $k\n"); continue; } $dict[$k] = $v; } ksort($dict, SORT_STRING); $files[$strKey] = json_encode($info + $dict, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) . "\n"; if (!preg_match('/"version"\s*:\s*"(\d+)\.(\d+)\.(\d+)"/', $files[$manKey], $m)) { fwrite(STDERR, "Version nicht gefunden.\n"); exit(1); } $ver = $m[1] . '.' . $m[2] . '.' . ((int) $m[3] + 1); $files[$manKey] = preg_replace('/("version"\s*:\s*")\d+\.\d+\.\d+(")/', '${1}' . $ver . '${2}', $files[$manKey], 1); @unlink($out); $z = new ZipArchive(); $z->open($out, ZipArchive::CREATE); ksort($files); foreach ($files as $name => $content) $z->addFromString($name, $content); $z->close(); echo basename($out), ' Version ', $ver, ' (', count($dict), ' Texte) ', hash_file('sha256', $out), "\n";