about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKevin Mandura <webmaster@kevin-mandura.de>2024-03-30 13:36:55 +0100
committerKevin Mandura <webmaster@kevin-mandura.de>2024-03-30 13:36:55 +0100
commitfb2880af7115bc990a3f71453d905bedf4914c72 (patch)
treea9703d7781bba72a69e4fd41b59993cef4cf5d78
parent7364b0a6a91bd28dca0a7b20c4ef505686521fca (diff)
downloadktls-website-main.tar.gz
ktls-website-main.zip
Fix incorrect HTML lang code HEAD main
If the client happens to request a page in a language, for which there
are no translations available (→ fallback language), the HTML lang
attribute would incorrectly contain the client's requested language
rather than the actual language, that is used for the HTML page.

Separating the $locale variable into $requestedLocale and $usedLocale
solves this problem and makes the purpose of the variables more clear.
-rw-r--r--includes/global.inc.php8
-rw-r--r--includes/templates/partials/footer.inc.php2
-rw-r--r--includes/templates/partials/header.inc.php2
-rw-r--r--public/contact.php2
4 files changed, 8 insertions, 6 deletions
diff --git a/includes/global.inc.php b/includes/global.inc.php
index 91cdb24..9001f11 100644
--- a/includes/global.inc.php
+++ b/includes/global.inc.php
@@ -231,15 +231,17 @@ if (CHECK_IMPORTANT_FILES === true) {
    The fallback language to use is defined inside
    'config.inc.php'.
  */
-$locale = getLocale(); // e.g. "de"
+$requestedLocale = getLocale(); // e.g. "de"
 
 /* Initialize to use fallback language */
 $useFallbackLanguage = true;
-if (isTranslationAvailable($locale) === true) {
-  define("TRANSLATIONS", parse_ini_file(__ROOT__ . '/includes/translations/'.$locale.'.ini', true));
+if (isTranslationAvailable($requestedLocale) === true) {
+  define("TRANSLATIONS", parse_ini_file(__ROOT__ . '/includes/translations/'.$requestedLocale.'.ini', true));
   $useFallbackLanguage = false;
+  $usedLocale = $requestedLocale; // requested locale will be used
 } else {
   define("TRANSLATIONS", parse_ini_file(__ROOT__ . '/includes/translations/' . FALLBACK_LANGUAGE . '.ini', true));
+  $usedLocale = FALLBACK_LANGUAGE; // fall back locale is used instead of the requested one
 }
 
 /* Build PAGES associative array from translation ini file.
diff --git a/includes/templates/partials/footer.inc.php b/includes/templates/partials/footer.inc.php
index 97fbb63..c091af2 100644
--- a/includes/templates/partials/footer.inc.php
+++ b/includes/templates/partials/footer.inc.php
@@ -32,7 +32,7 @@ foreach ($translationFiles as $translationFile) {
   /* To indicate the currently applied language, check whether the iterating translation file is used */
   $translationLanguageCode = substr($translationFile, -6, 2); /* e.g. "de */
 
-  if ($translationLanguageCode === $locale || ($useFallbackLanguage === true && $translationLanguageCode === FALLBACK_LANGUAGE)) { ?>
+  if ($translationLanguageCode === $requestedLocale || ($useFallbackLanguage === true && $translationLanguageCode === FALLBACK_LANGUAGE)) { ?>
           <li class="strong"><?= $translationTitle ?></li>
 <?php } else { ?>
   <li><a href="/formhandling/save-language<?= $phpext ?>?lang=<?= $translationLanguageCode ?>&originpage=<?= str_replace("%2Findex.php", "%2F", urlencode($_SERVER['PHP_SELF'])) ?>"><?= $translationTitle ?></a></li>
diff --git a/includes/templates/partials/header.inc.php b/includes/templates/partials/header.inc.php
index d5b7e9d..5dcd414 100644
--- a/includes/templates/partials/header.inc.php
+++ b/includes/templates/partials/header.inc.php
@@ -1,5 +1,5 @@
 <!DOCTYPE html>
-<html lang="<?= $locale ?>" dir="ltr">
+<html lang="<?= $usedLocale ?>" dir="ltr">
   <head>
     <meta charset="UTF-8">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
diff --git a/public/contact.php b/public/contact.php
index 9f4d5d8..b70ded5 100644
--- a/public/contact.php
+++ b/public/contact.php
@@ -19,7 +19,7 @@ require_once(__ROOT__ . "/includes/functions/logIP.inc.php");
 if ($useFallbackLanguage === true)
   $securityQuestionLanguage = FALLBACK_LANGUAGE;
 else
-  $securityQuestionLanguage = $locale;
+  $securityQuestionLanguage = $usedLocale;
 
 $sql = "SELECT COUNT(*) FROM security_questions WHERE lang=?;";
 $stmt = mysqli_stmt_init($dbConn);