ss
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
* Sammelt alle verwendeten Übersetzungs-Keys aus:
|
* Sammelt alle verwendeten Übersetzungs-Keys aus:
|
||||||
* - /public/landingpage/{*}/{*}
|
* - /public/landingpage/{*}/{*}
|
||||||
* - /partials/landing/{*}/{*}
|
* - /partials/landing/{*}/{*}
|
||||||
* - /partials/structure/{*}/{*}
|
* - /partials/structure/{*}.php
|
||||||
* - (optional) /partials/partials/{*}/{*}, falls vorhanden
|
* - (optional) /partials/partials/{*}/{*}, falls vorhanden
|
||||||
*
|
*
|
||||||
* und trägt fehlende Keys in public/assets/i18n/de.json ein.
|
* und trägt fehlende Keys in public/assets/i18n/de.json ein.
|
||||||
@@ -111,11 +111,10 @@ function simpleKeyExistsRecursive(array $data, string $key): bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fügt einen einfachen Key unter $data['auto'] hinzu,
|
* Fügt einen einfachen Key irgendwo in der Struktur ein
|
||||||
* sofern er nicht irgendwo in der Struktur bereits existiert.
|
* (früher unter $data['auto'], jetzt nur noch für Reste).
|
||||||
*
|
*
|
||||||
* WICHTIG: $defaultValue ist explizit nullable, um
|
* WICHTIG: $defaultValue ist explizit nullable → keine Deprecation.
|
||||||
* deprecation unter PHP 8.4+ zu vermeiden.
|
|
||||||
*/
|
*/
|
||||||
function addSimpleKey(array &$data, string $key, ?string $defaultValue = null): void
|
function addSimpleKey(array &$data, string $key, ?string $defaultValue = null): void
|
||||||
{
|
{
|
||||||
@@ -139,7 +138,9 @@ function addSimpleKey(array &$data, string $key, ?string $defaultValue = null):
|
|||||||
/**
|
/**
|
||||||
* Key einfügen, mit optionalem Default-Text.
|
* Key einfügen, mit optionalem Default-Text.
|
||||||
* Dot-Notation → verschachtelt,
|
* Dot-Notation → verschachtelt,
|
||||||
* Simple-Key → unter "auto".
|
* Simple-Key → (Rest) unter "auto".
|
||||||
|
*
|
||||||
|
* Dynamische Keys mit $ (z.B. pages.$pageKey.meta.title) werden ignoriert.
|
||||||
*/
|
*/
|
||||||
function addKeyToData(array &$data, string $key, ?string $defaultValue = null): void
|
function addKeyToData(array &$data, string $key, ?string $defaultValue = null): void
|
||||||
{
|
{
|
||||||
@@ -202,6 +203,9 @@ function extractInlineTextForDataI18n(string $content, int $matchOffset, int $ma
|
|||||||
*
|
*
|
||||||
* Rückgabe:
|
* Rückgabe:
|
||||||
* [ 'key1' => 'Default-Text oder null', 'key2' => null, ... ]
|
* [ 'key1' => 'Default-Text oder null', 'key2' => null, ... ]
|
||||||
|
*
|
||||||
|
* Dynamische Keys mit $ (pages.$pageKey...) werden bereits hier
|
||||||
|
* ignoriert.
|
||||||
*/
|
*/
|
||||||
function collectKeysFromFile(string $file): array
|
function collectKeysFromFile(string $file): array
|
||||||
{
|
{
|
||||||
@@ -219,6 +223,10 @@ function collectKeysFromFile(string $file): array
|
|||||||
$fullOffset = $m[0][1];
|
$fullOffset = $m[0][1];
|
||||||
$key = trim($m[2][0]);
|
$key = trim($m[2][0]);
|
||||||
|
|
||||||
|
if (strpos($key, '$') !== false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Versuche, den Inline-Text zu extrahieren: >Text<
|
// Versuche, den Inline-Text zu extrahieren: >Text<
|
||||||
$inlineText = extractInlineTextForDataI18n($content, $fullOffset, strlen($fullMatch));
|
$inlineText = extractInlineTextForDataI18n($content, $fullOffset, strlen($fullMatch));
|
||||||
|
|
||||||
@@ -241,7 +249,6 @@ function collectKeysFromFile(string $file): array
|
|||||||
foreach ($m2 as $match) {
|
foreach ($m2 as $match) {
|
||||||
$key = trim($match[2]);
|
$key = trim($match[2]);
|
||||||
|
|
||||||
// Dynamische Keys mit Variablen wie pages.$pageKey.* hier sofort ignorieren
|
|
||||||
if (strpos($key, '$') !== false) {
|
if (strpos($key, '$') !== false) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -269,7 +276,6 @@ function collectKeysFromFile(string $file): array
|
|||||||
foreach ($m3 as $match) {
|
foreach ($m3 as $match) {
|
||||||
$key = trim($match[2]);
|
$key = trim($match[2]);
|
||||||
|
|
||||||
// Auch hier dynamische Keys mit $ ignorieren
|
|
||||||
if (strpos($key, '$') !== false) {
|
if (strpos($key, '$') !== false) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -315,9 +321,40 @@ foreach ($scanDirs as $dir) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$filePath = $fileInfo->getPathname();
|
$filePath = $fileInfo->getPathname();
|
||||||
|
$relPath = str_replace($baseDir . DIRECTORY_SEPARATOR, '', $filePath);
|
||||||
|
|
||||||
$keysInFile = collectKeysFromFile($filePath);
|
$keysInFile = collectKeysFromFile($filePath);
|
||||||
|
|
||||||
foreach ($keysInFile as $key => $defaultText) {
|
foreach ($keysInFile as $key => $defaultText) {
|
||||||
|
$origKey = $key;
|
||||||
|
|
||||||
|
// Nur für einfache Keys (ohne Punkt) Kontext-basiert umschreiben
|
||||||
|
if (strpos($key, '.') === false) {
|
||||||
|
|
||||||
|
// 4a) partials/landing/{slug}/{section}.php
|
||||||
|
if (preg_match('~^partials/landing/([^/]+)/([^/]+)\.(php|html?|phtml)$~', $relPath, $m)) {
|
||||||
|
$slug = $m[1]; // z.B. landing, fakecheck, login, dashboard
|
||||||
|
$section = $m[2]; // z.B. hero, how, problem, features, security, faq, main
|
||||||
|
|
||||||
|
$key = "pages.$slug.sections.$section.$key";
|
||||||
|
|
||||||
|
// 4b) public/landingpage/{slug}/*.php → Fallback: section "main"
|
||||||
|
} elseif (preg_match('~^public/landingpage/([^/]+)/.+\.(php|html?|phtml)$~', $relPath, $m)) {
|
||||||
|
$slug = $m[1]; // z.B. landing, fakecheck, login, dashboard
|
||||||
|
|
||||||
|
$key = "pages.$slug.sections.main.$key";
|
||||||
|
|
||||||
|
// 4c) partials/structure/{name}.php → z.B. header.*, footer.*
|
||||||
|
} elseif (preg_match('~^partials/structure/([^/]+)\.(php|html?|phtml)$~', $relPath, $m)) {
|
||||||
|
$section = $m[1]; // header, footer, layout_start, layout_end, app_config, ...
|
||||||
|
|
||||||
|
// Für header/footer/… legen wir den Root so an, wie die Datei heißt:
|
||||||
|
// header_slogan → header.header_slogan
|
||||||
|
$key = $section . '.' . $key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gefilterten Key übernehmen
|
||||||
if (!array_key_exists($key, $foundKeys)) {
|
if (!array_key_exists($key, $foundKeys)) {
|
||||||
$foundKeys[$key] = $defaultText;
|
$foundKeys[$key] = $defaultText;
|
||||||
} else {
|
} else {
|
||||||
@@ -366,7 +403,7 @@ if (is_dir($landingRoot)) {
|
|||||||
|
|
||||||
$slug = $entry->getFilename();
|
$slug = $entry->getFilename();
|
||||||
|
|
||||||
// sehr simple Heuristik: Landingpage gilt als "aktiv", wenn irgendeine .php drin liegt
|
// einfache Heuristik: Landingpage gilt als "aktiv", wenn irgendeine .php drin liegt
|
||||||
$hasPhp = false;
|
$hasPhp = false;
|
||||||
foreach (new DirectoryIterator($entry->getPathname()) as $file) {
|
foreach (new DirectoryIterator($entry->getPathname()) as $file) {
|
||||||
if ($file->isFile() && strtolower($file->getExtension()) === 'php') {
|
if ($file->isFile() && strtolower($file->getExtension()) === 'php') {
|
||||||
|
|||||||
Reference in New Issue
Block a user