-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlanguage_loader.php
More file actions
38 lines (33 loc) · 1.06 KB
/
language_loader.php
File metadata and controls
38 lines (33 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
/**
* file: language_loader.php
*
* Handles internationalization (i18n) by loading the appropriate language file.
*
* Determines the language based on URL parameter ('lang'), session data, or cookies.
* Falls back to Dutch if no valid language is found.
*/
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
// Default language is Dutch
$default_lang = 'dutch';
// Check if a language is set in the session or cookie
if (isset($_GET['lang'])) {
$lang_choice = $_GET['lang'];
$_SESSION['lang'] = $lang_choice;
setcookie('lang', $lang_choice, time() + (86400 * 30), "/"); // 30 day cookie
} elseif (isset($_SESSION['lang'])) {
$lang_choice = $_SESSION['lang'];
} elseif (isset($_COOKIE['lang'])) {
$lang_choice = $_COOKIE['lang'];
} else {
$lang_choice = $default_lang;
}
// Check if the language file exists, otherwise fall back to the default
$lang_file = 'languages/' . $lang_choice . '.lang.inc.php';
if (!file_exists($lang_file)) {
$lang_file = 'languages/' . $default_lang . '.lang.inc.php';
}
require_once $lang_file;
?>