Fix language-specific page loading and correct en/uk naming
- 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)
This commit is contained in:
parent
79eb010fa5
commit
bea9cdfb0c
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user