svalavuo 6 дней назад
Родитель
Сommit
4fbf9ac5dd
6 измененных файлов с 90 добавлено и 40 удалено
  1. 1 0
      .gitignore
  2. 41 0
      debug_language.php
  3. 34 0
      debug_redirect.php
  4. 0 1
      includes/.gitignore
  5. 0 32
      includes/config.php
  6. 14 7
      includes/translation.php

+ 1 - 0
.gitignore

@@ -1 +1,2 @@
+test_*
 includes/config.php

+ 41 - 0
debug_language.php

@@ -0,0 +1,41 @@
+<?php
+// Debug language detection issue
+session_start();
+
+echo "=== Language Detection Debug ===\n\n";
+
+// Check if session is working
+echo "Session ID: " . session_id() . "\n";
+echo "Session data: " . print_r($_SESSION, true) . "\n\n";
+
+// Check GET parameters
+echo "GET parameters: " . print_r($_GET, true) . "\n\n";
+
+// Check browser language
+echo "Browser language: " . ($_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? 'not set') . "\n\n";
+
+// Check constants
+echo "DEFAULT_LANGUAGE constant: " . (defined('DEFAULT_LANGUAGE') ? DEFAULT_LANGUAGE : 'not defined') . "\n\n";
+
+// Initialize translation system
+require_once 'includes/config.php';
+require_once 'includes/translation.php';
+
+echo "After loading config:\n";
+echo "DEFAULT_LANGUAGE constant: " . (defined('DEFAULT_LANGUAGE') ? DEFAULT_LANGUAGE : 'not defined') . "\n\n";
+
+try {
+    $translation = Translation::getInstance();
+    echo "Current language: " . $translation->getCurrentLanguage() . "\n";
+    echo "Supported languages: " . implode(', ', array_keys($translation->getSupportedLanguages())) . "\n";
+    echo "Session language after init: " . ($_SESSION['language'] ?? 'not set') . "\n\n";
+    
+    // Test translation
+    echo "Test translation 'nav_home': " . $translation->translate('nav_home') . "\n";
+    
+} catch (Exception $e) {
+    echo "Error: " . $e->getMessage() . "\n";
+}
+
+echo "\n=== Debug Complete ===\n";
+?>

+ 34 - 0
debug_redirect.php

@@ -0,0 +1,34 @@
+<?php
+// Debug the redirect issue
+session_start();
+
+echo "=== Debug Redirect Issue ===\n\n";
+
+require_once 'includes/config.php';
+
+// Simulate the exact scenario
+$_GET['lang'] = 'fi';
+$_SERVER['REQUEST_URI'] = '/index.php?lang=fi';
+
+echo "Before Translation initialization:\n";
+echo "GET lang: " . $_GET['lang'] . "\n";
+echo "REQUEST_URI: " . $_SERVER['REQUEST_URI'] . "\n";
+echo "Session language: " . ($_SESSION['language'] ?? 'not set') . "\n\n";
+
+// This should trigger the redirect, but let's see what happens
+try {
+    require_once 'includes/translation.php';
+    
+    echo "After Translation initialization:\n";
+    echo "Session language: " . ($_SESSION['language'] ?? 'not set') . "\n";
+    
+    $translation = Translation::getInstance();
+    echo "Current language: " . $translation->getCurrentLanguage() . "\n";
+    echo "Translation test: " . $translation->translate('nav_home') . "\n";
+    
+} catch (Exception $e) {
+    echo "Exception: " . $e->getMessage() . "\n";
+}
+
+echo "\n=== Debug Complete ===\n";
+?>

+ 0 - 1
includes/.gitignore

@@ -1 +0,0 @@
-config.php

+ 0 - 32
includes/config.php

@@ -1,32 +0,0 @@
-<?php
-/**
- * Site Configuration
- */
-
-// Database settings
-define('DB_HOST', '10.8.10.31');
-define('DB_NAME', 'valtsu_webpub');
-define('DB_USER', 'root');
-define('DB_PASS', 'jotainaivanmuuta');
-
-// Site settings
-define('SITE_TITLE', 'Publication System');
-define('DEFAULT_LANGUAGE', 'fi');
-
-// LDAP settings
-define('LDAP_ENABLED', true);
-define('LDAP_HOST', '10.8.10.11');
-define('LDAP_PORT', 389);
-define('LDAP_BASE_DN', 'dc=valavuo,dc=net');
-define('LDAP_BIND_DN', 'uid=zimbra,cn=admins,cn=zimbra');
-define('LDAP_BIND_PASS', 'lLKmZlpf0');
-define('LDAP_USER_FILTER', '(&(|(uid={username})(cn={username})(sn={username})(givenName={username})(mail={username}))(objectclass=zimbraAccount)(zimbraAccountStatus=active))');
-
-// Security settings
-define('SESSION_LIFETIME', 3600); // 1 hour
-define('PASSWORD_MIN_LENGTH', 8);
-
-// Error reporting
-error_reporting(E_ALL);
-ini_set('display_errors', 1);
-?>

+ 14 - 7
includes/translation.php

@@ -35,6 +35,9 @@ class Translation {
             $this->currentLanguage = $_GET['lang'];
             $_SESSION['language'] = $this->currentLanguage;
             
+            // Load translations for the new language immediately
+            $this->loadTranslations();
+            
             // Redirect to same page without language parameter to apply new language
             $currentUrl = $_SERVER['REQUEST_URI'];
             $parsedUrl = parse_url($currentUrl);
@@ -50,9 +53,13 @@ class Translation {
                 }
             }
             
-            // Redirect to clean URL
-            header('Location: ' . $redirectUrl);
-            exit;
+            // Only redirect if not in CLI mode to avoid issues during testing
+            if (php_sapi_name() !== 'cli') {
+                // Redirect to clean URL
+                header('Location: ' . $redirectUrl);
+                exit;
+            }
+            return;
         }
         
         // Check browser language preference
@@ -65,14 +72,14 @@ class Translation {
             }
         }
         
-        // Check configuration default
-        if (defined('DEFAULT_LANGUAGE') && isset($this->supportedLanguages[DEFAULT_LANGUAGE])) {
+        // Check configuration default (but prefer English for public site)
+        if (defined('DEFAULT_LANGUAGE') && isset($this->supportedLanguages[DEFAULT_LANGUAGE]) && DEFAULT_LANGUAGE !== 'fi') {
             $this->currentLanguage = DEFAULT_LANGUAGE;
             return;
         }
         
-        // Fall back to default language
-        $this->currentLanguage = $this->defaultLanguage;
+        // Fall back to English as default language
+        $this->currentLanguage = 'en';
     }
     
     private function loadTranslations() {