From bea9cdfb0c0502c8ab2a4f83a75e73c08892f458 Mon Sep 17 00:00:00 2001 From: Edwin Noorlander Date: Sat, 22 Nov 2025 16:21:22 +0100 Subject: [PATCH] Fix language-specific page loading and correct en/uk naming MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix getPage() to search for language-specific files (en.test.md, nl.test.md) - Correct guide file naming: uk.codepress.md → en.codepress.md - Update scanDirectory() filtering: uk → en for consistency - Update formatDisplayName() cleaning: uk → en for consistency - Language-specific pages now load correctly without 404 errors - Pages display with clean names (without language prefixes) --- engine/core/class/CodePressCMS.php | 29 ++++++++++++++++------ guide/{uk.codepress.md => en.codepress.md} | 0 2 files changed, 22 insertions(+), 7 deletions(-) rename guide/{uk.codepress.md => en.codepress.md} (100%) diff --git a/engine/core/class/CodePressCMS.php b/engine/core/class/CodePressCMS.php index ac3630a..4901408 100644 --- a/engine/core/class/CodePressCMS.php +++ b/engine/core/class/CodePressCMS.php @@ -110,10 +110,10 @@ class CodePressCMS { if ($item[0] === '.') continue; // Skip language-specific content that doesn't match current language - if (preg_match('/^(nl|uk)\./', $item)) { + if (preg_match('/^(nl|en)\./', $item)) { $langPrefix = substr($item, 0, 2); if (($langPrefix === 'nl' && $this->currentLanguage !== 'nl') || - ($langPrefix === 'uk' && $this->currentLanguage !== 'en')) { + ($langPrefix === 'en' && $this->currentLanguage !== 'en')) { continue; } } @@ -257,6 +257,22 @@ class CodePressCMS { } } + // If no exact match found, check for language-specific versions + if (!isset($result)) { + $langPrefix = $this->currentLanguage; + + if (file_exists($this->config['content_dir'] . '/' . $langPrefix . '.' . $page . '.md')) { + $actualFilePath = $this->config['content_dir'] . '/' . $langPrefix . '.' . $page . '.md'; + $result = $this->parseMarkdown(file_get_contents($actualFilePath)); + } elseif (file_exists($this->config['content_dir'] . '/' . $langPrefix . '.' . $page . '.php')) { + $actualFilePath = $this->config['content_dir'] . '/' . $langPrefix . '.' . $page . '.php'; + $result = $this->parsePHP($actualFilePath); + } elseif (file_exists($this->config['content_dir'] . '/' . $langPrefix . '.' . $page . '.html')) { + $actualFilePath = $this->config['content_dir'] . '/' . $langPrefix . '.' . $page . '.html'; + $result = $this->parseHTML(file_get_contents($actualFilePath)); + } + } + // If no file found, check if it's a directory if (!isset($result) && is_dir($filePath)) { return $this->getDirectoryListing($page, $filePath); @@ -519,8 +535,8 @@ class CodePressCMS { * @return string Formatted display name */ private function formatDisplayName($filename) { - // Remove language prefixes (nl. or uk.) from display names - if (preg_match('/^(nl|uk)\.(.+)$/', $filename, $matches)) { + // Remove language prefixes (nl. or en.) from display names + if (preg_match('/^(nl|en)\.(.+)$/', $filename, $matches)) { $filename = $matches[2]; } @@ -641,11 +657,10 @@ class CodePressCMS { */ private function getGuidePage() { $lang = $this->currentLanguage; - $langCode = ($lang === 'en') ? 'uk' : $lang; // Map 'en' to 'uk' for file naming - $guideFile = __DIR__ . '/../../../guide/' . $langCode . '.codepress.md'; + $guideFile = __DIR__ . '/../../../guide/' . $lang . '.codepress.md'; if (!file_exists($guideFile)) { - $guideFile = __DIR__ . '/../../../guide/uk.codepress.md'; // Fallback to English (UK) + $guideFile = __DIR__ . '/../../../guide/en.codepress.md'; // Fallback to English } $content = file_get_contents($guideFile); diff --git a/guide/uk.codepress.md b/guide/en.codepress.md similarity index 100% rename from guide/uk.codepress.md rename to guide/en.codepress.md