make web default language configurable
authorKonrad Rosenbaum <konrad@silmor.de>
Sun, 27 Sep 2015 17:04:44 +0000 (19:04 +0200)
committerKonrad Rosenbaum <konrad@silmor.de>
Sun, 27 Sep 2015 17:04:44 +0000 (19:04 +0200)
www/config.php.template
www/inc/classes/language_manager.php
www/inc/wext/format.php

index 7646ad9..438a792 100644 (file)
@@ -84,6 +84,11 @@ $ClientSessionTimeout=2*3600;
 //Template directory
 $template="./template/";
 
+//set this if you want to set a default language
+//it must exist as a directory inside the template directory
+//if unset the pseudo-language "C" will be used
+$default_language="en";
+
 //Renderer options
 $twigoptions = array(
   //cache points to:
index 24fdf0f..65ed82d 100644 (file)
@@ -1,8 +1,9 @@
 <?php
 // +----------------------------------------------------------------------
-// | PHP Source                                                           
+// | PHP Source
 // +----------------------------------------------------------------------
-// | Copyright (C) 2007 by Peter keller <peter@silmor.de>
+// | Copyright (C) 2007-8 by Peter keller <peter@silmor.de>
+// |           (c) 2010-15 Konrad Rosenbaum <konrad@silmor.de>
 // +----------------------------------------------------------------------
 // |
 // | Copyright: See COPYING file that comes with this distribution
@@ -41,7 +42,6 @@ function string_format($string, $array)
 class LanguageManager
 {
        private static $instance=null;//will be instantiated by singleton()
-       private $lang="C";//fallback for unknown language, constructor overrides it
        private $config;
        private $templateFolder;
        private $formatcfg;
@@ -101,7 +101,12 @@ class LanguageManager
        /** returns the instance of the Language Manager */
        public static function singleton()
        {
+                global $default_language;
                if(self::$instance===null) {
+                        //this may be set in config.php, otherwise use "C"
+                        if(!isset($default_language))
+                                $default_language="C";
+                        //instantiate LM
                        self::$instance = new LanguageManager();
                }
                
@@ -124,9 +129,10 @@ class LanguageManager
        /**returns the configured language template folder plus its fallback*/
        public function templateFolders()
        {
+                global $default_language;
                $ret=array();
                $ret[]=realpath($this->templateFolder());
-               $ret[]=realpath($this->templateFolder."C/");
+               $ret[]=realpath($this->templateFolder.$default_language."/");
                return $ret;
        }
        
index 9162031..b5f9a60 100644 (file)
@@ -19,9 +19,10 @@ class WOServerFormat extends WOServerFormatAbstract
 //                     echo "Loading ".$lang."<br/>";
                        $this->loadConfig($template."/".$lang."/format.cfg");
                }else{
+                        global $default_language;
                        //fall back to default language
 //                     echo "Loading C as fallback<br/>";
-                       $this->loadConfig($template."/C/format.cfg");
+                       $this->loadConfig($template."/".$default_language."/format.cfg");
                }
                //check timezone
                $tz=$this->gettimezone();