Implement language-specific content system

- Rename guide files: nl.md → nl.codepress.md, en.md → uk.codepress.md
- Add language filtering in scanDirectory() for nl.* and uk.* files/folders
- Update formatDisplayName() to remove language prefixes from display names
- Update getGuidePage() to use new naming convention (en → uk mapping)
- Content with nl. prefix only shows when Dutch language is selected
- Content with uk. prefix only shows when English language is selected
This commit is contained in:
Edwin Noorlander 2025-11-22 16:14:59 +01:00
parent 9bb21579f7
commit 79eb010fa5
3 changed files with 17 additions and 2 deletions

View File

@ -109,6 +109,15 @@ class CodePressCMS {
foreach ($items as $item) {
if ($item[0] === '.') continue;
// Skip language-specific content that doesn't match current language
if (preg_match('/^(nl|uk)\./', $item)) {
$langPrefix = substr($item, 0, 2);
if (($langPrefix === 'nl' && $this->currentLanguage !== 'nl') ||
($langPrefix === 'uk' && $this->currentLanguage !== 'en')) {
continue;
}
}
$path = $dir . '/' . $item;
$relativePath = $prefix ? $prefix . '/' . $item : $item;
@ -510,6 +519,11 @@ 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)) {
$filename = $matches[2];
}
// Handle special cases first
if (strtolower($filename) === 'phpinfo') {
return 'phpinfo';
@ -627,10 +641,11 @@ class CodePressCMS {
*/
private function getGuidePage() {
$lang = $this->currentLanguage;
$guideFile = __DIR__ . '/../../../guide/' . $lang . '.md';
$langCode = ($lang === 'en') ? 'uk' : $lang; // Map 'en' to 'uk' for file naming
$guideFile = __DIR__ . '/../../../guide/' . $langCode . '.codepress.md';
if (!file_exists($guideFile)) {
$guideFile = __DIR__ . '/../../../guide/en.md'; // Fallback to English
$guideFile = __DIR__ . '/../../../guide/uk.codepress.md'; // Fallback to English (UK)
}
$content = file_get_contents($guideFile);