Annotation of /mambo/branches/4.6/includes/mambolanguage.class.php
Parent Directory
|
Revision Log
Revision 870 - (view) (download)
| 1 : | csouza | 403 | <?php |
| 2 : | alwarren | 870 | /** |
| 3 : | * Language Class for Mambo | ||
| 4 : | * @package Mambo | ||
| 5 : | * @copyright (C) 2006 - 2007 Mambo Foundation Inc. | ||
| 6 : | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL | ||
| 7 : | * @author Mambo Foundation Inc see README.php | ||
| 8 : | */ | ||
| 9 : | csouza | 403 | |
| 10 : | class mamboLanguage { | ||
| 11 : | var $name = ''; | ||
| 12 : | var $path = ''; | ||
| 13 : | var $version = '4.6'; | ||
| 14 : | var $title = ''; | ||
| 15 : | var $description = ''; | ||
| 16 : | var $creationdate = ''; | ||
| 17 : | var $author = ''; | ||
| 18 : | var $authorurl = ''; | ||
| 19 : | var $authoremail = ''; | ||
| 20 : | var $copyright = ''; | ||
| 21 : | var $license = ''; | ||
| 22 : | var $territory = ''; | ||
| 23 : | var $text_direction = ''; | ||
| 24 : | var $date_format = ''; | ||
| 25 : | var $iso639 = ''; | ||
| 26 : | var $iso3166_2 = ''; | ||
| 27 : | var $iso3166_3 = ''; | ||
| 28 : | var $locale = ''; | ||
| 29 : | var $charset = ''; | ||
| 30 : | enjoyman | 822 | var $wincodepage = ''; |
| 31 : | csouza | 403 | var $codesets = array(); |
| 32 : | var $plural_form = array(); | ||
| 33 : | csouza | 459 | var $days = array('sun'=>'','mon'=>'','tue'=>'','wed'=>'','thu'=>'','fri'=>'','sat'=>''); |
| 34 : | var $months = array('jan'=>'','feb'=>'','mar'=>'','apr'=>'','may'=>'','jun'=>'','jul'=>'','aug'=>'','sep'=>'','oct'=>'','nov'=>'','dec'=>''); | ||
| 35 : | csouza | 403 | var $files = array(); |
| 36 : | |||
| 37 : | function mamboLanguage($lang, $path = null) { | ||
| 38 : | $this->name = $lang; | ||
| 39 : | $this->path = $path; | ||
| 40 : | csouza | 556 | if (is_null($this->path)) $this->path = mamboCore::get('rootPath').'/language/'; |
| 41 : | csouza | 403 | $this->load(); |
| 42 : | csouza | 407 | } |
| 43 : | csouza | 556 | |
| 44 : | csouza | 403 | function getFileName() { |
| 45 : | $file = $this->iso639; | ||
| 46 : | $file .= strlen($this->iso3166_2) == 2 ? '_' . $this->iso3166_2 : ''; | ||
| 47 : | return $file; | ||
| 48 : | csouza | 407 | } |
| 49 : | csouza | 403 | |
| 50 : | function get($var) { | ||
| 51 : | return isset($this->$var) ? $this->$var : null; | ||
| 52 : | csouza | 407 | } |
| 53 : | csouza | 403 | function set($var, $value) { |
| 54 : | if (isset($this->$var)) $this->$var = $value; | ||
| 55 : | csouza | 407 | } |
| 56 : | csouza | 403 | function save() { |
| 57 : | enjoyman | 822 | global $page_,$task; |
| 58 : | $this->updateFiles(); | ||
| 59 : | $xml = $this->toXML(); | ||
| 60 : | enjoyman | 866 | if( (($page_=="addpage") && ($task=="save")) || ($task=="convert") ){ |
| 61 : | enjoyman | 822 | if (strtolower($this->charset) != 'utf-8') { |
| 62 : | if(trim($this->wincodepage)!="") | ||
| 63 : | $xml = $this->iconvert("utf-8",$this->wincodepage,$xml); | ||
| 64 : | else | ||
| 65 : | $xml = $this->iconvert("utf-8",$this->charset,$xml,TRUE); | ||
| 66 : | } | ||
| 67 : | enjoyman | 812 | } |
| 68 : | csouza | 556 | /**/ |
| 69 : | csouza | 403 | $fp = fopen($this->path . $this->getFileName() . '.xml', 'w+'); |
| 70 : | csouza | 556 | fwrite($fp, $xml); |
| 71 : | csouza | 403 | fclose($fp); |
| 72 : | csouza | 407 | } |
| 73 : | csouza | 403 | |
| 74 : | function getLanguages() { | ||
| 75 : | $langfiles = glob($this->path . "*.xml"); | ||
| 76 : | foreach($langfiles as $xml) { | ||
| 77 : | $xml = str_replace($this->path, '', $xml); | ||
| 78 : | if (substr($xml, 0, -4) != 'locales') { | ||
| 79 : | csouza | 556 | $lobj = &new mamboLanguage(substr($xml, 0, -4), $this->path) ; |
| 80 : | csouza | 403 | $langs[$lobj->name] = $lobj; |
| 81 : | csouza | 407 | } |
| 82 : | } | ||
| 83 : | csouza | 403 | return $langs; |
| 84 : | csouza | 407 | } |
| 85 : | csouza | 403 | |
| 86 : | function setPlurals($exp) { | ||
| 87 : | preg_match('/nplurals\s*=\s*(\d+)\s*;\s*plural\s*=\s*(.*)\s*;/', $exp, $plurals); | ||
| 88 : | $this->plural_form = array('nplurals' => $plurals[1], 'plural' => $plurals[2], 'expression' => $plurals[0]); | ||
| 89 : | csouza | 407 | } |
| 90 : | csouza | 403 | |
| 91 : | function getDate($format = null, $timestamp = null) { | ||
| 92 : | if (is_null($format)) $format = $this->date_format; | ||
| 93 : | if (is_null($timestamp)) { | ||
| 94 : | $timestamp = time(); | ||
| 95 : | csouza | 407 | } |
| 96 : | csouza | 403 | $days = array_values($this->days); |
| 97 : | $months = array_values($this->months); | ||
| 98 : | $date = preg_replace('/%[aA]/', $days[(int)strftime('%w', $timestamp)], $format); | ||
| 99 : | $date = preg_replace('/%[bB]/', $months[(int)strftime('%m', $timestamp)-1], $date); | ||
| 100 : | return strftime($date, $timestamp); | ||
| 101 : | csouza | 407 | } |
| 102 : | csouza | 403 | |
| 103 : | function load($load_catalogs = false) { | ||
| 104 : | if (is_readable($this->path . $this->name . ".xml")) { | ||
| 105 : | csouza | 556 | $source = file_get_contents($this->path . $this->name . ".xml"); |
| 106 : | if (preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/m', $source, $m)) { | ||
| 107 : | $encoding = strtoupper($m[1]); | ||
| 108 : | } else { | ||
| 109 : | $encoding = "UTF-8"; | ||
| 110 : | } | ||
| 111 : | |||
| 112 : | if($encoding == "UTF-8" || $encoding == "US-ASCII" || $encoding == "ISO-8859-1") { | ||
| 113 : | $parser = xml_parser_create($encoding); | ||
| 114 : | } else { | ||
| 115 : | |||
| 116 : | #if(function_exists('mb_convert_encoding')) { | ||
| 117 : | enjoyman | 822 | if(trim($this->wincodepage)!="") |
| 118 : | $encoded_source = $this->iconvert($this->wincodepage,"UTF-8",$source); | ||
| 119 : | else | ||
| 120 : | $encoded_source = $this->iconvert($encoding,"UTF-8",$source,TRUE); | ||
| 121 : | csouza | 556 | # } |
| 122 : | |||
| 123 : | if($encoded_source != NULL) { | ||
| 124 : | $source = str_replace ( $m[0],'<?xml version="1.0" encoding="utf-8"?>', $encoded_source); | ||
| 125 : | } | ||
| 126 : | |||
| 127 : | $parser = xml_parser_create("UTF-8"); | ||
| 128 : | } | ||
| 129 : | |||
| 130 : | xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); | ||
| 131 : | xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); | ||
| 132 : | xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); | ||
| 133 : | if (!xml_parse_into_struct($parser, implode("", file($this->path . $this->name . ".xml")), $values)) { | ||
| 134 : | die(sprintf("XML error: %s at ".$this->path . $this->name.".xml in line %d", | ||
| 135 : | xml_error_string(xml_get_error_code($parser)), | ||
| 136 : | xml_get_current_line_number($parser))); | ||
| 137 : | } | ||
| 138 : | xml_parser_free($parser); | ||
| 139 : | |||
| 140 : | |||
| 141 : | csouza | 403 | foreach($values as $key => $value) { |
| 142 : | $tag = strtolower($value['tag']); | ||
| 143 : | switch ($tag) { | ||
| 144 : | case 'name': | ||
| 145 : | csouza | 407 | $this->title = $value['value']; |
| 146 : | andphe | 861 | $this->lang = strtolower($value['value']); |
| 147 : | csouza | 407 | break; |
| 148 : | csouza | 403 | case 'author': |
| 149 : | case 'creationdate': | ||
| 150 : | case 'copyright': | ||
| 151 : | case 'license': | ||
| 152 : | case 'authoremail': | ||
| 153 : | case 'authorurl': | ||
| 154 : | case 'version': | ||
| 155 : | case 'description': | ||
| 156 : | csouza | 407 | $this->$tag = $value['value']; |
| 157 : | break; | ||
| 158 : | csouza | 403 | case 'locale': |
| 159 : | csouza | 407 | if ($value['type'] == 'open') { |
| 160 : | foreach ($value['attributes'] as $k => $v) | ||
| 161 : | $this->$k = $v; | ||
| 162 : | } | ||
| 163 : | break; | ||
| 164 : | csouza | 403 | case 'date_format': |
| 165 : | csouza | 407 | $this->date_format = $value['value']; |
| 166 : | break; | ||
| 167 : | csouza | 403 | case 'plural_form': |
| 168 : | csouza | 407 | if (!empty($value['attributes']['expression'])) { |
| 169 : | $this->plural_form = $value['attributes']; | ||
| 170 : | } | ||
| 171 : | break; | ||
| 172 : | csouza | 403 | case 'charset': |
| 173 : | csouza | 407 | $this->codesets[] = $value['value']; |
| 174 : | break; | ||
| 175 : | enjoyman | 822 | case 'wincodepage': |
| 176 : | $this->wincodepage = $value['value']; | ||
| 177 : | break; | ||
| 178 : | csouza | 403 | case 'days': |
| 179 : | csouza | 407 | $this->days = $value['attributes']; |
| 180 : | break; | ||
| 181 : | csouza | 403 | case 'months': |
| 182 : | csouza | 407 | $this->months = $value['attributes']; |
| 183 : | break; | ||
| 184 : | csouza | 403 | case 'filename': |
| 185 : | csouza | 407 | if ($load_catalogs) { |
| 186 : | $file = $value['attributes']; | ||
| 187 : | $file['filename'] = $value['value']; | ||
| 188 : | $this->files[] = $file; | ||
| 189 : | } | ||
| 190 : | break; | ||
| 191 : | } | ||
| 192 : | } | ||
| 193 : | csouza | 556 | $this->codesets = array_unique($this->codesets); |
| 194 : | enjoyman | 866 | if( class_exists('ConvertCharset') || function_exists('iconv') ) |
| 195 : | enjoyman | 822 | { |
| 196 : | enjoyman | 866 | if(strtolower($encoding)!="utf-8") |
| 197 : | enjoyman | 822 | { |
| 198 : | enjoyman | 866 | $attrs = get_object_vars($this); |
| 199 : | if(trim($this->wincodepage)!="") | ||
| 200 : | enjoyman | 822 | { |
| 201 : | enjoyman | 866 | $this->arrayEncoding($attrs,$this->wincodepage); |
| 202 : | $this->bindAttributes($attrs); | ||
| 203 : | |||
| 204 : | }else{ | ||
| 205 : | enjoyman | 822 | $this->arrayEncoding($attrs,$encoding,TRUE); |
| 206 : | $this->bindAttributes($attrs); | ||
| 207 : | } | ||
| 208 : | } | ||
| 209 : | } | ||
| 210 : | return true; | ||
| 211 : | } | ||
| 212 : | return false; | ||
| 213 : | } | ||
| 214 : | function iconvert($fromcharset,$tocharset,$source,$useiconv=FALSE) | ||
| 215 : | { | ||
| 216 : | if($useiconv) | ||
| 217 : | { | ||
| 218 : | if(function_exists('iconv')) | ||
| 219 : | { | ||
| 220 : | return iconv($fromcharset,$tocharset,$source); | ||
| 221 : | }else | ||
| 222 : | { | ||
| 223 : | return FALSE; | ||
| 224 : | } | ||
| 225 : | } | ||
| 226 : | enjoyman | 866 | $NewEncoding = new ConvertCharset(); |
| 227 : | return $NewEncoding->Convert($source,$fromcharset,$tocharset,false); | ||
| 228 : | enjoyman | 822 | } |
| 229 : | enjoyman | 820 | function bindAttributes($attrs) |
| 230 : | enjoyman | 812 | { |
| 231 : | enjoyman | 820 | if(!is_array($attrs)) |
| 232 : | return false; | ||
| 233 : | foreach($attrs as $key=>$v) | ||
| 234 : | enjoyman | 812 | { |
| 235 : | enjoyman | 820 | $this->$key = $v; |
| 236 : | } | ||
| 237 : | } | ||
| 238 : | enjoyman | 822 | function arrayEncoding(&$attrs,$encoding,$useiconv=FALSE) |
| 239 : | enjoyman | 820 | { |
| 240 : | if(is_array($attrs)) | ||
| 241 : | { | ||
| 242 : | foreach($attrs as $key=>$val) | ||
| 243 : | enjoyman | 812 | { |
| 244 : | enjoyman | 820 | if(is_array($val)) |
| 245 : | enjoyman | 822 | $this->arrayEncoding($attrs[$key],$encoding,$useiconv); |
| 246 : | else | ||
| 247 : | enjoyman | 812 | { |
| 248 : | enjoyman | 822 | $attrs[$key] = $this->iconvert("utf-8",$encoding,$val,$useiconv); |
| 249 : | } | ||
| 250 : | enjoyman | 820 | } |
| 251 : | enjoyman | 812 | } |
| 252 : | } | ||
| 253 : | csouza | 403 | |
| 254 : | function updateFiles() { | ||
| 255 : | $dir = $this->path . $this->name . '/'; | ||
| 256 : | $langfiles = mosReadDirectory($dir, '.po$'); | ||
| 257 : | csouza | 466 | set_time_limit(60); |
| 258 : | csouza | 556 | |
| 259 : | csouza | 403 | foreach ($langfiles as $lf) { |
| 260 : | $domain = substr($lf, 0, -3); | ||
| 261 : | $catalog = new PHPGettext_Catalog($domain, $this->path); | ||
| 262 : | $catalog->setproperty('lang', $this->name); | ||
| 263 : | $catalog->setproperty('mode', _MODE_PO_); | ||
| 264 : | $catalog->load(); | ||
| 265 : | $file['filename'] = "language/" . $this->name . '/' . $lf; | ||
| 266 : | $file['domain'] = $domain; | ||
| 267 : | $file['strings'] = count($catalog->strings); | ||
| 268 : | $file['percent'] = ''; | ||
| 269 : | $file['translated'] = 0; | ||
| 270 : | $file['fuzzy'] = 0; | ||
| 271 : | csouza | 407 | $pluralfuzz = false; |
| 272 : | csouza | 403 | foreach ($catalog->strings as $msg) { |
| 273 : | csouza | 556 | if (is_array($msg->msgstr)) { |
| 274 : | foreach ($msg->msgstr as $i) { | ||
| 275 : | $unt = empty($i); | ||
| 276 : | } | ||
| 277 : | if (!$unt) { | ||
| 278 : | $file['translated']++; | ||
| 279 : | } | ||
| 280 : | } | ||
| 281 : | csouza | 403 | if (!is_array($msg->msgstr) && !empty($msg->msgstr) && !$msg->is_fuzzy) { |
| 282 : | $file['translated']++; | ||
| 283 : | csouza | 556 | } |
| 284 : | csouza | 407 | if ($msg->is_fuzzy) { |
| 285 : | csouza | 403 | $file['fuzzy']++; |
| 286 : | csouza | 407 | } |
| 287 : | } | ||
| 288 : | csouza | 556 | |
| 289 : | |||
| 290 : | csouza | 403 | $nonfuzzy = $file['strings'] - $file['fuzzy']; |
| 291 : | if (!$nonfuzzy) $nonfuzzy = 1; | ||
| 292 : | $file['percent'] = round($file['translated'] * 100 / $nonfuzzy, 2); | ||
| 293 : | unset($nonfuzzy); | ||
| 294 : | $this->files[] = $file; | ||
| 295 : | csouza | 407 | } |
| 296 : | } | ||
| 297 : | csouza | 403 | |
| 298 : | function toXML() { | ||
| 299 : | $array[] = array('tag' => 'mosinstall', 'type' => 'open', 'level' => 1, 'attributes' => array('version' => '4.6', 'type' => 'language')); | ||
| 300 : | $array[] = array('tag' => 'name', 'type' => 'complete', 'level' => 2, 'value' => $this->title); | ||
| 301 : | $array[] = array('tag' => 'version', 'type' => 'complete', 'level' => 2, 'value' => $this->version); | ||
| 302 : | $array[] = array('tag' => 'description', 'type' => 'complete', 'level' => 2, 'value' => $this->description); | ||
| 303 : | $array[] = array('tag' => 'creationdate', 'type' => 'complete', 'level' => 2, 'value' => $this->creationdate); | ||
| 304 : | $array[] = array('tag' => 'author', 'type' => 'complete', 'level' => 2, 'value' => $this->author); | ||
| 305 : | $array[] = array('tag' => 'authorurl', 'type' => 'complete', 'level' => 2, 'value' => $this->authorurl); | ||
| 306 : | $array[] = array('tag' => 'authoremail', 'type' => 'complete', 'level' => 2, 'value' => $this->authoremail); | ||
| 307 : | $array[] = array('tag' => 'copyright', 'type' => 'complete', 'level' => 2, 'value' => $this->copyright); | ||
| 308 : | $array[] = array('tag' => 'license', 'type' => 'complete', 'level' => 2, 'value' => $this->license); | ||
| 309 : | $array[] = array('tag' => 'params', 'type' => 'open', 'level' => 2); | ||
| 310 : | $array[] = array('tag' => 'param', 'type' => 'complete', 'level' => 3, 'attributes' => array('name' => 'locale', 'type' => 'text', 'default' => $this->locale, 'label' => 'Locale String', 'description' => 'Locale string for setlocale() (eg. en, english)')); | ||
| 311 : | $array[] = array('tag' => 'param', 'type' => 'complete', 'level' => 3, 'attributes' => array('name' => 'charset', 'type' => 'text', 'default' => $this->charset, 'label' => 'Character Set', 'description' => 'Character set for this language.')); | ||
| 312 : | $array[] = array('tag' => 'param', 'type' => 'complete', 'level' => 3, 'attributes' => array('name' => 'text_direction', 'type' => 'text', 'default' => $this->text_direction, 'label' => 'Text Direction', 'description' => 'left-to-right or light-to-left')); | ||
| 313 : | $array[] = array('tag' => 'param', 'type' => 'complete', 'level' => 3, 'attributes' => array('name' => 'date_format', 'type' => 'text', 'default' => $this->date_format, 'label' => 'Date Format', 'description' => 'Date format for strftime() (eg. %A, %d %B %Y)')); | ||
| 314 : | $array[] = array('tag' => 'param', 'type' => 'complete', 'level' => 3, 'attributes' => array('name' => 'plural_form', 'type' => 'text', 'default' => htmlentities($this->plural_form['expression']), 'label' => 'Plural Forms', 'description' => 'Plural Forms expression')); | ||
| 315 : | enjoyman | 822 | $array[] = array('tag' => 'params', 'type' => 'close', 'level' => 2); |
| 316 : | csouza | 403 | $array[] = array('tag' => 'locale', 'type' => 'open', 'level' => 2, 'attributes' => array('name' => $this->name, 'title' => $this->title, 'territory' => $this->territory, 'locale' => $this->locale, 'text_direction' => $this->text_direction, 'iso639' => $this->iso639, 'iso3166_2' => $this->iso3166_2, 'iso3166_3' => $this->iso3166_3, 'charset' => $this->charset)); |
| 317 : | $array[] = array('tag' => 'plural_form', 'type' => 'complete', 'level' => 3, 'attributes' => array('nplurals' => $this->plural_form['nplurals'] , 'plural' => htmlentities($this->plural_form['plural']), 'expression' => htmlentities($this->plural_form['expression']))); | ||
| 318 : | $array[] = array('tag' => 'date_format', 'type' => 'complete', 'level' => 3, 'value' => $this->date_format); | ||
| 319 : | $array[] = array('tag' => 'codesets', 'type' => 'open', 'level' => 3); | ||
| 320 : | foreach ($this->codesets as $charset) $array[] = array('tag' => 'charset', 'type' => 'complete', 'level' => 4, 'value' => $charset); | ||
| 321 : | $array[] = array('tag' => 'codesets', 'type' => 'close', 'level' => 3); | ||
| 322 : | enjoyman | 822 | $array[] = array('tag' => 'wincodepage', 'type' => 'complete', 'level' => 3,'value'=>$this->wincodepage); |
| 323 : | csouza | 403 | foreach ($this->days as $name => $day) $days[$name] = $day; |
| 324 : | $array[] = array('tag' => 'days', 'type' => 'complete', 'level' => 3, 'attributes' => $days); | ||
| 325 : | foreach ($this->months as $name => $month) $months[$name] = $month; | ||
| 326 : | $array[] = array('tag' => 'months', 'type' => 'complete', 'level' => 3, 'attributes' => $months); | ||
| 327 : | $array[] = array('tag' => 'locale', 'type' => 'close', 'level' => 2); | ||
| 328 : | $array[] = array('tag' => 'files', 'type' => 'open', 'level' => 2); | ||
| 329 : | foreach ($this->files as $file) { | ||
| 330 : | $array[] = array('tag' => 'filename', 'type' => 'complete', 'level' => 3, 'value' => $file['filename'], 'attributes' => array('domain' => $file['domain'] , 'strings' => $file['strings'] , 'translated' => $file['translated'] , 'fuzzy' => $file['fuzzy'] , 'percent' => $file['percent'])); | ||
| 331 : | csouza | 407 | } |
| 332 : | csouza | 403 | $array[] = array('tag' => 'files', 'type' => 'close', 'level' => 2); |
| 333 : | $array[] = array('tag' => 'mosinstall', 'type' => 'close', 'level' => 1); | ||
| 334 : | |||
| 335 : | $xml = "<?xml version=\"1.0\" encoding=\"$this->charset\"?>\n"; | ||
| 336 : | if ((!empty($array)) AND (is_array($array))) { | ||
| 337 : | foreach ($array as $key => $value) { | ||
| 338 : | switch ($value["type"]) { | ||
| 339 : | case "open": | ||
| 340 : | csouza | 407 | $xml .= str_repeat("\t", $value["level"] - 1); |
| 341 : | $xml .= "<" . strtolower($value["tag"]); | ||
| 342 : | if (isset($value["attributes"])) { | ||
| 343 : | foreach ($value["attributes"] as $k => $v) { | ||
| 344 : | $xml .= sprintf(' %s="%s"', strtolower($k), $v); | ||
| 345 : | } | ||
| 346 : | } | ||
| 347 : | $xml .= ">\n"; | ||
| 348 : | break; | ||
| 349 : | csouza | 403 | case "complete": |
| 350 : | csouza | 407 | $xml .= str_repeat("\t", $value["level"] - 1); |
| 351 : | $xml .= "<" . strtolower($value["tag"]); | ||
| 352 : | if (isset($value["attributes"])) { | ||
| 353 : | foreach ($value["attributes"] as $k => $v) { | ||
| 354 : | $xml .= sprintf(' %s="%s"', strtolower($k), $v); | ||
| 355 : | } | ||
| 356 : | } | ||
| 357 : | $xml .= ">"; | ||
| 358 : | $xml .= isset($value['value']) ? $value['value'] : false; | ||
| 359 : | $xml .= "</" . strtolower($value["tag"]) . ">\n"; | ||
| 360 : | break; | ||
| 361 : | csouza | 403 | case "close": |
| 362 : | csouza | 407 | $xml .= str_repeat("\t", $value["level"] - 1); |
| 363 : | $xml .= "</" . strtolower($value["tag"]) . ">\n"; | ||
| 364 : | break; | ||
| 365 : | csouza | 403 | default: |
| 366 : | csouza | 407 | break; |
| 367 : | } | ||
| 368 : | } | ||
| 369 : | } | ||
| 370 : | csouza | 403 | return $xml; |
| 371 : | csouza | 407 | } |
| 372 : | csouza | 403 | |
| 373 : | csouza | 556 | function getLocales() { |
| 374 : | $xmlfile = "../language/locales.xml"; | ||
| 375 : | $p = xml_parser_create(); | ||
| 376 : | xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0); | ||
| 377 : | xml_parser_set_option($p, XML_OPTION_SKIP_WHITE, 1); | ||
| 378 : | xml_parse_into_struct($p, implode("", file($xmlfile)), $values); | ||
| 379 : | xml_parser_free($p); | ||
| 380 : | $locales = array(); | ||
| 381 : | foreach($values as $key => $value) { | ||
| 382 : | switch ($value['tag']) { | ||
| 383 : | case 'locale': | ||
| 384 : | if ($value['type'] == 'open') { | ||
| 385 : | $iso639 = $value['attributes']['iso639']; | ||
| 386 : | $language[$iso639] = $value['attributes']['title']; | ||
| 387 : | $locale[$iso639] = $value['attributes']; | ||
| 388 : | $directions[$iso639] = $value['attributes']['text_direction']; | ||
| 389 : | } | ||
| 390 : | break; | ||
| 391 : | case 'territory': | ||
| 392 : | $t['iso3166_2'] = $value['attributes']['iso3166_2']; | ||
| 393 : | $t['iso3166_3'] = $value['attributes']['iso3166_3']; | ||
| 394 : | $t['territory'] = $value['value']; | ||
| 395 : | $territories[$iso639][] = $t; | ||
| 396 : | break; | ||
| 397 : | case 'charset': | ||
| 398 : | $locale[$iso639]['codesets'][] = $codesets[$iso639][] = $value['value']; | ||
| 399 : | break; | ||
| 400 : | case 'date_format': | ||
| 401 : | $locale[$iso639]['dateformats'] = $dateformats[$iso639] = $value['value']; | ||
| 402 : | break; | ||
| 403 : | enjoyman | 822 | case 'wincodepage': |
| 404 : | $locale[$iso639]['wincodepage'] = $value['value']; | ||
| 405 : | break; | ||
| 406 : | case 'days': | ||
| 407 : | csouza | 556 | $locale[$iso639]['days'] = $value['attributes']; |
| 408 : | break; | ||
| 409 : | case 'months': | ||
| 410 : | $locale[$iso639]['months'] = $value['attributes']; | ||
| 411 : | break; | ||
| 412 : | case 'plural_form': | ||
| 413 : | $exp = ''; | ||
| 414 : | if (!empty($value['attributes']['expression'])) { | ||
| 415 : | $locale[$iso639]['plural_form'] = $value['attributes']; | ||
| 416 : | $plural_forms[$iso639] = $value['attributes']['expression']; | ||
| 417 : | } | ||
| 418 : | break; | ||
| 419 : | csouza | 407 | } |
| 420 : | } | ||
| 421 : | csouza | 556 | $locales['locales'] = $locale; |
| 422 : | $locales['languages'] = $language; | ||
| 423 : | $locales['territories'] = $territories; | ||
| 424 : | $locales['codesets'] = $codesets; | ||
| 425 : | $locales['dateformats'] = $dateformats; | ||
| 426 : | $locales['directions'] = $directions; | ||
| 427 : | $locales['plural_forms'] = $plural_forms; | ||
| 428 : | return $locales; | ||
| 429 : | csouza | 407 | } |
| 430 : | } | ||
| 431 : | csouza | 403 | |
| 432 : | csouza | 556 | function getlocales() { |
| 433 : | return mamboLanguage::getLocales(); | ||
| 434 : | } | ||
| 435 : | csouza | 403 | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

