From 5dd9a2a1bdebdc629b9f3ebdf957fb3ccc5acf88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Sajdl?= Date: Sun, 7 Jan 2018 20:43:04 +0100 Subject: [PATCH] Add template doc, fixup rendering locale select --- classes/locale-negotiator.php | 7 ++- config.php.template | 3 +- template.php | 105 +++++++++++++++++++--------------- 3 files changed, 65 insertions(+), 50 deletions(-) diff --git a/classes/locale-negotiator.php b/classes/locale-negotiator.php index 613d16b..77935cb 100644 --- a/classes/locale-negotiator.php +++ b/classes/locale-negotiator.php @@ -14,12 +14,13 @@ class LocaleNegotiator */ function __construct($default_language) { - $tmp = glob(__DIR__ . '/locale/*' , GLOB_ONLYDIR); + $tmp = glob(__DIR__ . '/../locale/*' , GLOB_ONLYDIR); $this->default_language = $default_language; //Works only if the server supports the locale //This basically means $accepted_langs[] = ""; - foreach ($accepted_langs as $key => $value) { - $this->accepted_langs[basename($value)] = self::mb_ucfirst(locale_get_display_language($lang, $lang)); + foreach ($tmp as $key => $value) { + $lang = basename($value); + $this->accepted_langs[$lang] = self::mb_ucfirst(locale_get_display_language($lang, $lang)); } } diff --git a/config.php.template b/config.php.template index 5149d86..c42fc9a 100644 --- a/config.php.template +++ b/config.php.template @@ -11,10 +11,11 @@ define("DEFAULT_LANGUAGE", "en_GB"); require("classes/locale-negotiator.php"); +$negotiator = new LocaleNegotiator(DEFAULT_LANGUAGE); + if (!isset($_SESSION['locale'])||isset($_GET['lang'])) { $override = ((isset($_GET['lang']))?$_GET['lang']:null); - $negotiator = new LocaleNegotiator(DEFAULT_LANGUAGE); $best_match = $negotiator->negotiate($override); $_SESSION['locale'] = $best_match; setlocale(LC_ALL, $_SESSION['locale'].".UTF-8"); diff --git a/template.php b/template.php index 5b0408d..e419921 100644 --- a/template.php +++ b/template.php @@ -1,5 +1,13 @@
- -
-
-
-
-
Copyright © Vojtěch Sajdl
-
-
- - - -
+ /** + * Renders footer + * @param Boolean $admin decides whether to load admin scripts + */ + public static function render_footer($admin = false) + { + global $negotiator; + $lang_names = $negotiator->get_accepted_langs(); + ?> +
+
+
+
+
Copyright © Vojtěch Sajdl
+
+
+ + +
-
-
-
-
- - - - - - - - - - - - +
+
+
+
+ + + + + + + + + + + +