forked from jpatokal/openflights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocale.php
59 lines (54 loc) · 1.61 KB
/
locale.php
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
session_set_cookie_params(['samesite' => 'Strict']);
session_start();
include 'config.php';
if ($OF_USE_LOCALES) {
if (isset($_GET["lang"])) {
$locale = $_GET["lang"];
$_SESSION["locale"] = $locale;
} else {
$locale = $_SESSION["locale"] ?? "en_US";
}
$locale .= ".utf8";
setlocale(LC_ALL, $locale);
if (substr_count($_SERVER['SCRIPT_NAME'], '/') == 1) {
$path = ".";
} else {
$path = "..";
}
bindtextdomain("messages", $path . "/locale");
textdomain("messages");
header("Content-type: text/html; charset=utf-8");
} else {
$locale = "en_US.utf8";
function _($string) {
return $string;
}
}
/**
* Generate select box (pulldown) with all known locales
* Box ID is "locale" and it triggers JS changeLocale() when selection is changed
*
* @param $dbh PDO OpenFlights DB handler
* @param $locale string Currently selected locale
*/
function locale_pulldown($dbh, $locale) {
global $OF_USE_LOCALES;
echo "<select id='locale' onChange='JavaScript:changeLocale()'>\n";
if ($OF_USE_LOCALES) {
$sql = "SELECT * FROM locales ORDER BY name ASC";
foreach ($dbh->query($sql) as $row) {
$selected = ($row["locale"] . ".utf8" == $locale ? "SELECTED" : "");
printf(
"<option value='%s' %s>%s (%s)</option>\n",
$row["locale"],
$selected,
$row["name"],
substr($row["locale"], 0, 2)
);
}
} else {
echo "<option value='en_US' SELECTED>English</option>\n";
}
echo "</select>";
}