Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

locale process (See related posts)

// description of your code here


/**
 * Enter description here...
 * 
 * @author chenn 
 * @version $Id: Local.php 56 2006-04-11 14:04:39Z chenn $
 */
class Local {
        
        /**
         * Enter description here...
         * 
         * @var string
         */
        private static $lang;
        
        /**
         * local language code, eg. zh_CN, es_ES, etc
         *
         * @var unknown_type
         */
        private $language;
        
        /**
         * Enter description here...
         *
         * @var string
         */
        private $encoding = "UTF-8";
        
        
        function __construct($language) {
                $this->language = $language;
                $this->encoding = DEFAULT_ENCODING;
                $this->loadLocal();
        }
        
        /**
         * Load local language pakege
         *
         */
        private function loadLocal() {
                if (self::$lang == null) {
                        $lang = array();
                        $filename = ROOT_PATH . "language/lang_" . $this->language . ".php";
                        if (is_readable($filename)) {
                                include_once($filename);
                        }
                        
                        if ($handle = opendir(ROOT_PATH . "plugins/")) {
                            while (false !== ($file = readdir($handle))) {
                                if ($file != "." && $file != "..") {
                                    $pLang = ROOT_PATH . "plugins/$file/language/lang_" 
                                                        . $this->language . ".php"; 
                                    if (is_file($pLang)) {
                                        include_once($pLang);
                                    }
                                }
                            }
                            closedir($handle);
                        }

                        // $lang is defined in the lang_xx.php file
                        self::$lang = $lang;
                        unset($lang);
                }
        }
        
        
        /**
         * Get the translated string by key
         *
         * @param       string $key
         * @return      string
         */
        public function getString($key) {
                if (array_key_exists($key, self::$lang)) {
                        return self::$lang[$key];
                } else {
                        return $key;
                }
        }
        
        /**
         * Enter description here...
         *
         * @return array
         */
        public function getStrings() {
                return self::$lang;
        }
        
}

?>

You need to create an account or log in to post comments to this site.


Related Posts