core

Changeset 24916

Show
Ignore:
Timestamp:
11/29/08 08:59:08 (6 weeks ago)
Author:
bp
Message:

added gettext functionality to Zikula.class and LanguageUtil?.class and locale files

Location:
development/main
Files:
7 added
2 removed
6 modified

Legend:

Unmodified
Added
Removed
  • development/main/includes/BlockUtil.class.php

    r24768 r24916  
    7474            $blockinfo = self::getInfo($blockplacement['bid']); 
    7575            // block filtering 
     76//bp 2008-02-12 - if session variable 'area' is set retrieve it     
     77            $area = SessionUtil::getVar('area',null); 
     78 
    7679            if (!empty($blockinfo['filter']['modules']) || 
    7780                !empty($blockinfo['filter']['type']) || 
     
    9295                if (!empty($blockinfo['filter']['customargs'])) { 
    9396                    $blockinfo['filter']['customargs'] = explode(',', $blockinfo['filter']['customargs']); 
    94                     $customargs = array(); 
    95                     static $filtervars = array('module', 'name', 'type', 'func', 'theme', 'authid'); 
    96                     foreach ($_GET as $var => $value) { 
     97                    $customargs = array(); 
     98                    static $filtervars = array('module', 'name', 'type', 'func', 'theme', 'authid'); 
     99 
     100// bp                    foreach ($_GET as $var => $value) { 
     101                    $_get = $_GET; 
     102                    if (isset($area)) { 
     103                            $_get['area'] = $area; 
     104                    } 
     105                    foreach ($_get as $var => $value) { 
     106// end bp 
     107 
    97108                        if (!in_array($var, $filtervars)) { 
    98109                            $customargs[] = DataUtil::formatForOS(strip_tags($var)) . '=' . DataUtil::formatForOS(strip_tags($value)); 
     
    102113                } 
    103114            } 
     115//bp area set but empty customargs  -> we hide the block            
     116                if (!empty($area) && empty($blockinfo['filter']['customargs'])) continue; 
     117 
    104118            // dont display the block if it's not active or not in matching langauge 
    105119            if (!$blockinfo['active'] || (!empty($blockinfo['language']) && $blockinfo['language'] != $currentlang)) continue; 
  • development/main/includes/DBConnectionStack.class.php

    r24728 r24916  
    119119        } 
    120120*/ 
     121 
     122        // ensure mysql handles utf-8 ok. 
     123        // bplagge - 2008/11/18 
     124        if (!defined('_PNINSTALLVER') && ($dbdriver == 'mysql' || $dbdriver == 'mysqli')) { 
     125                if (isset($dbcharset)) { 
     126                        $cs = str_replace('-','', strtolower($dbcharset)); 
     127                        $conn->Execute("set names $cs"); 
     128                } 
     129        } 
    121130 
    122131        $GLOBALS['PNRuntime']['DB'][$count]             = $GLOBALS['PNConfig']['DBInfo'][$name]; 
  • development/main/includes/LanguageUtil.class.php

    r24768 r24916  
    141141    static function setLocale($category, $locale)  
    142142    { 
    143         $winos = stristr(getenv('OS'),'windows'); 
    144         !isset($category) ? $category = "LC_ALL" : ""; 
    145         is_array($locale) ? implode(',', $locale) : ''; 
    146         $result = setlocale($category, $locale); 
    147  
    148         $p = strpos($result, '.'); 
    149         if ($p > 0) { 
    150             $encoding = substr($result, $p + 1); 
    151             if ($winos) { 
    152                 $encoding = 'CP' . $encoding; 
    153                 } 
    154         } 
    155         # ensure that we always return the valid character set 
    156         empty($encoding) ? $encoding = _CHARSET : ''; 
    157         # session variable is used in DateUtil 
    158         SessionUtil::setVar('encoding', $encoding); 
     143         $winos = stristr(getenv('OS'),'windows'); 
     144        !isset($category) ? $category = "LC_ALL" : "";          
     145 
     146                $envlanguage = Zikula::getConfigVar('syslocale'); 
     147         
     148        // set the LANGUAGE environment variable 
     149        # NOTE: if the locale to set is not included in LANGUAGE environment variable translations won't work! 
     150                $re = putenv("LANGUAGE=$envlanguage"); 
     151        /* 
     152                $lv = getenv('LANGUAGE'); 
     153                echo "putenv returned: $re language environment var set to: $lv<br>"; 
     154        */ 
     155 
     156        /* debug 
     157                if (is_Array($locale)) { 
     158                        print_r($locale); echo "<br>"; 
     159                } else {                 
     160                        echo "locale: $locale<br>";         
     161                } 
     162        */  
     163         
     164        $encoding = setlocale($category, $locale); 
     165 
     166        /* 
     167                echo "encoding: $encoding<br>"; 
     168        */ 
     169 
     170        if ($winos) { 
     171            $enc = 'CP' . $encoding; 
     172            } else { 
     173                $p = strpos($encoding, '.'); 
     174                $enc = ($p > 0) ? substr($encoding, $p+1) : $encoding;           
     175            } 
     176        # setlocale return value but: 
     177        # Linux: without charset, Windows: CP. prefix 
     178                SessionUtil::setVar('encoding', $enc); 
     179 
    159180        return $encoding; 
    160181        } 
     182         
    161183 
    162184   /** 
     
    178200 
    179201    /** 
    180      * This file sets textdomain and locale for gettext error messages 
    181      * It is included in the ../modules/MailingList/pntables.php file 
     202     * This function sets textdomain and locale for gettext error messages 
    182203     * @param    $modname         module name - lowercase only 
    183204     * @param    $bindtextdom     defaults to the module name - lowercase only 
     
    207228    static function initGettext($modname = '') { 
    208229 
    209         $winos = stristr(getenv('OS'), 'windows'); 
    210         $syscharset = _CHARSET; 
    211         $syslocale = $winos ? _LOCALEWIN : _LOCALE; 
    212         $locarray = array(_LOCALE, _LOCALEWIN); 
    213         $sysdomain = "zikula"; 
     230                $winos = stristr(getenv('OS'),'windows'); 
     231                $syscharset = Zikula::getConfigVar('syscharset'); 
     232                $syslocale  = Zikula::getConfigVar('syslocale'); 
     233                $sysdom = Zikula::getConfigVar('sysdom');                
    214234 
    215235        $currentlang = LanguageUtil::getUserLang(); 
     
    219239        } 
    220240 
    221         if (isset($modname)) { 
     241                if (!empty($modname)) {          
    222242            $modinfo = ModuleUtil::getInfo(ModuleUtil::getIDFromName($modname)); 
    223243            if (!$modinfo) { 
     
    232252            $usmoddir = "config/locale/$directory";  
    233253                } else { 
    234             // use $sysdomain 
    235             $dom = strtolower($sysdomain); 
     254            // use $sysdom 
     255            $dom = strtolower($sysdom); 
    236256            $locdir = "locale"; 
    237257                } 
     
    252272        $locdir = $b . '/' . $locdir; 
    253273 
    254         $enc = LanguageUtil::setLocale(LC_ALL, $locarray); 
    255         if (!$enc) { 
    256             ($winos) ? $loc = _LOCALEWIN : $loc = _LOCALE; 
    257             LogUtil::registerError(__fGT(_('Could not set locale to %s'), array(array($loc, true)))); 
    258         } 
     274                $extlocale = $syslocale.'.'.$syscharset; 
     275                $locarray       = array($extlocale, $syslocale); 
     276                $enc = LanguageUtil::setLocale(LC_ALL, $locarray); 
     277                 
     278                if (!$enc) { 
     279                        LogUtil::registerError (__fGT( _('Could not set locale to %s'), array( array($syslocale, true)))); 
     280                } 
    259281 
    260282        $rt = bindtextdomain($dom, $locdir); 
     
    263285        // this is important for languages like Japanese which can be encoded using different character sets 
    264286        $rc = bind_textdomain_codeset($dom, $syscharset); 
    265         $rd = textdomain($dom); 
     287 
     288        // we only set the textdomain for a module 
     289        if (isset($modname)) { 
     290                $rd=textdomain($dom); 
     291                }  
    266292 
    267293        return array($enc, $syscharset); 
  • development/main/includes/Renderer.class.php

    r24885 r24916  
    254254        // lastly the theme paths 
    255255        $this->assign('themepath',     $this->baseurl . 'themes/' . $theme); 
    256         $this->assign('stylepath',     $this->baseurl . 'themes/' . $theme . '/style'); 
     256        //bp 2008-11-17 add $themedom variable 
     257        $this->assign('themedom', $this->themeinfo['name']); 
     258        // end bp 
     259        $this->assign('stylepath',     $this->baseurl . 'themes/' . $theme . '/style'); 
    257260        $this->assign('scriptpath',    $this->baseurl . 'themes/' . $theme . '/javascript'); 
    258261        $this->assign('imagepath',     $this->baseurl . 'themes/' . $theme . '/images'); 
  • development/main/includes/Theme.class.php

    r24768 r24916  
    5959        protected $isloggedin; 
    6060 
     61        //bp 2008-02-11 
     62        // area, logical subset of the website (similar to category 
     63        protected $area; 
     64 
    6165        /** 
    6266         * Initialize our class 
     
    143147            } 
    144148 
     149            //bp 2008-11-17 - bindtextdomain 
     150            //the name of the theme's textdomain must correspond to the name defined in pnversion.php! 
     151            //e.g. $themeversion['name'] = sql_ledger; 
     152            $syscharset = Zikula::getConfigVar('syscharset'); 
     153 
     154            // we need the absolute path! 
     155            $ldir = dirname(__FILE__); 
     156            $p = strpos($ldir, '/includes'); 
     157            $b = substr($ldir, 0, $p); 
     158 
     159            $themelocpath = $b."/".$this->themepath.'/locale'; 
     160 
     161            $rt = bindtextdomain($this->name, $themelocpath); 
     162            $rc = bind_textdomain_codeset($this->name, $syscharset); 
     163 
     164            //debug 
     165            /* 
     166               $loc =        setlocale(LC_ALL,0);  
     167               echo "syscharset: $syscharset, locale: $loc, themelocpath: $themelocpath, themedom: $this->name<br/> 
     168                        bindtextdomain: $rt, bind_textdomain_codeset: $rc<br/>"; 
     169                echo dgettext($this->name, 'Home'); 
     170                 
     171                echo "<br/>set textdomain<br/>"; 
     172                $rd=textdomain($this->name); 
     173                echo _('Home');                  
     174             */ 
     175            //end bp         
     176 
    145177            // Start the output buffering to capture module output 
    146178            ob_start(); 
     
    277309            // 1. Master template path 
    278310            $masterpath = "themes/$os_theme/templates"; 
     311 
     312            //bp 2008-02-11 area template path -> so we can specify area-specific templates 
     313            $areapath = "themes/$os_theme/templates/category"; 
     314            //bp end 
     315 
    279316            // 2. The module template path 
    280317            $modulepath = "themes/$os_theme/templates/modules"; 
     
    284321            $ostemplate = DataUtil::formatForOS($template); 
    285322 
     323            //bp 2008-02-11 - add $areapath and subdir for module to the search path 
    286324            $search_path = array($masterpath, 
     325                                 $areapath, 
     326                                 $areapath.'/'.$modulepath, 
    287327                                 $modulepath, 
    288328                                 $blockpath); 
     
    434474            } 
    435475 
     476//bp 2008-02-11 - extract and save area id 
     477            foreach ($queryparts as $querypart) { 
     478                    if (stristr($querypart, 'area=')) { 
     479                            $n = strpos($querypart, '='); 
     480                            $this->area = substr($querypart, $n+1); 
     481                            $this->assign('area', $this->area); 
     482                            SessionUtil::setVar('area', $this->area); 
     483                    } 
     484            } 
     485            $this->area = SessionUtil::getVar('area',null); 
     486//bp 
     487 
     488 
    436489            // identify and load the correct module configuration 
    437490            $this->cachepage = true; 
     
    443496                $this->cachepage = false; 
    444497                $file = $pageconfigurations['*admin']['file']; 
     498//bp 2008-02-11 
     499            } else if (isset($this->area) && isset($pageconfigurations[$this->area])) { 
     500                    $file = $pageconfigurations[$this->area]['file']; 
     501//bp 
    445502            } else { 
    446503                $customargs = $this->module.'/'.$this->type.'/'.$this->func.$customargs; 
  • development/main/includes/Zikula.class.php

    r24778 r24916  
    254254            // Load our language files 
    255255            pnLangLoad(); 
     256 
     257            //bp 2008-11-17 
     258            // set config variable $sysdom, $syscharset 
     259            $sysdom = $GLOBALS['PNConfig']['System']['dom']; 
     260            !$sysdom ? $sysdom = 'zikula' : ''; 
     261            Zikula::setConfigVar('sysdom', $sysdom); 
     262            $syscharset = $GLOBALS['PNConfig']['DBInfo']['default']['dbcharset']; 
     263            !$syscharset ? $syscharset = 'UTF-8' : ''; 
     264            Zikula::setConfigVar('syscharset', $syscharset); 
     265            // locale is currently only set in the old language files 
     266            $winos = stristr(getenv('OS'),'windows'); 
     267            $syslocale  = $winos ?  _LOCALEWIN : _LOCALE; 
     268            Zikula::setConfigVar('syslocale', $syslocale); 
     269 
     270            // bp 2008-11-17 initialize Gettext 
     271            list($lc, $cs) = LanguageUtil::initGettext(); 
     272 
     273            /* debug 
     274               echo "syscharset: $syscharset<br/>"; 
     275               echo "sysdom: $sysdom, lc: $lc, cs: $cs<br/>"; 
     276               echo dgettext('zikula', 'Home'); 
     277               echo "<br/>set textdomain<br/>"; 
     278               $rd=textdomain($sysdom); 
     279               echo _('Home'); 
     280             */ 
    256281        } 
    257282 
 
 
Powered by Trac
Design by Arcsin