Add template doc, fixup rendering locale select

This commit is contained in:
Vojtěch Sajdl 2018-01-07 20:43:04 +01:00
parent 61f563c9b0
commit 5dd9a2a1bd
No known key found for this signature in database
GPG Key ID: 5D4EB1361A272390
3 changed files with 65 additions and 50 deletions

View File

@ -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[<lang_code>] = "<lang name>";
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));
}
}

View File

@ -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");

View File

@ -1,5 +1,13 @@
<?php
class Template(){
/**
* Class that encapsulates methods to render header and footer
*/
class Template{
/**
* Renders header
* @param String $page_name name of the page to be displayed as title
* @param Boolean $admin decides whether to show admin menu
*/
public static function render_header($page_name, $admin = false){
if (!$admin)
{
@ -77,9 +85,14 @@ class Template(){
}
}
/**
* Renders footer
* @param Boolean $admin decides whether to load admin scripts
*/
public static function render_footer($admin = false)
{
global $lang_names;
global $negotiator;
$lang_names = $negotiator->get_accepted_langs();
?>
</div>
<div id="footerwrap">
@ -119,6 +132,6 @@ class Template(){
<script src="/js/main.js"></script>
</body>
</html>
<?
<?
}
}