| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 lmb_require('limb/config/src/lmbIni.class.php'); 10 lmb_require('limb/i18n/src/locale/lmbLocaleSpec.class.php'); 11 12 /** 13 * Handles locale information and can format time, date, numbers and currency 14 * for correct display for a given locale. The locale conversion uses plain numerical values for 15 * dates, times, numbers and currency, if you want more elaborate conversions consider using the 16 * date, time, date_time and currency classes. 17 * 18 * Countries are specified by the ISO 3166 country Code 19 * http://www.iso.ch/iso/en/prods-services/iso3166ma/index.html 20 * User-assigned code elements 21 * http://www.iso.ch/iso/en/prods-services/iso3166ma/04background-on-iso-3166/reserved-and-user-assigned-codes.html#userassigned 22 * 23 * language is specified by the ISO 639 language Code 24 * http://www.w3.org/WAI/ER/IG/ert/iso639.htm 25 * 26 * currency/funds are specified by the ISO 4217 27 * http://www.bsi-global.com/Technical+Information/Publications/_Publications/tig90.xalter 28 * @package i18n 29 * @version $Id: lmbLocale.class.php 5945 2007-06-06 08:31:43Z pachanga $ 30 */ 31 class lmbLocale 32 { 33 protected $is_valid = false; 34 35 public $date_format = ''; // format of dates 36 public $short_date_format = ''; // format of short dates 37 public $time_format = ''; // format of times 38 public $date_time_format = ''; 39 public $short_date_time_format = ''; 40 public $short_date_short_time_format = ''; 41 public $short_time_format = ''; // format of short times 42 public $is_monday_first = false; // true if monday is the first day of the week 43 public $am_name = 'am'; 44 public $pm_name = 'pm'; 45 public $charset = ''; 46 public $LC_ALL = ''; 47 // numbers 48 public $decimal_symbol = ''; 49 public $thousand_separator = ''; 50 public $fract_digits = ''; 51 public $negative_symbol = ''; 52 public $positive_symbol = ''; 53 // currency 54 public $currency_name = ''; 55 public $currency_short_name = ''; 56 public $currency_decimal_symbol = ''; 57 public $currency_thousand_separator = ''; 58 public $currency_fract_digits = ''; 59 public $currency_negative_symbol = ''; 60 public $currency_positive_symbol = ''; 61 public $currency_symbol = ''; 62 public $currency_positive_format = ''; 63 public $currency_negative_format = ''; 64 // help arrays 65 public $short_month_names = array(); 66 public $long_month_names = array(); 67 public $short_day_names = array(); 68 public $long_day_names = array(); 69 public $week_days = array(0, 1, 2, 3, 4, 5, 6); 70 public $months = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); 71 72 public $country = ''; 73 public $country_comment = ''; 74 public $language_comment = ''; 75 76 public $language_name = ''; // name of the language 77 public $intl_language_name = ''; // internationalized name of the language 78 public $language_direction = 'ltr'; 79 80 protected $locale_spec; 81 82 function __construct($name, $config = null) 83 { 84 $this->locale_spec = new lmbLocaleSpec($name); 85 if($config) 86 $this->initLocaleSettings($config); 87 } 88 89 function initLocaleSettings($config) 90 { 91 if(!is_a($config, 'lmbIni')) 92 throw new lmbException('Config object must be an lmbIni instance', array('config' => $config)); 93 94 $this->_initCountrySettings($config); 95 $this->_initLanguageSettings($config); 96 } 97 98 function isValid() 99 { 100 return $this->is_valid; 101 } 102 103 protected function _initCountrySettings($config) 104 { 105 $config->assignOption($this->time_format, 'time_format', 'date_time'); 106 $config->assignOption($this->short_time_format, 'short_time_format', 'date_time'); 107 $config->assignOption($this->date_format, 'date_format', 'date_time'); 108 $config->assignOption($this->short_date_format, 'short_date_format', 'date_time'); 109 $config->assignOption($this->date_time_format, 'date_time_format', 'date_time'); 110 $config->assignOption($this->short_date_time_format, 'short_date_time_format', 'date_time'); 111 $config->assignOption($this->short_date_short_time_format, 'short_date_short_time_format', 'date_time'); 112 113 if($config->hasOption('is_monday_first', 'date_time')) 114 $this->is_monday_first = strtolower($config->getOption('is_monday_first', 'date_time')) == 'yes'; 115 116 if($this->is_monday_first) 117 $this->week_days = array(1, 2, 3, 4, 5, 6, 0); 118 else 119 $this->week_days = array(0, 1, 2, 3, 4, 5, 6); 120 121 $config->assignOption($this->country, 'country', 'regional_settings'); 122 $config->assignOption($this->country_comment, 'country_comment', 'regional_settings'); 123 124 $config->assignOption($this->decimal_symbol, 'decimal_symbol', 'numbers'); 125 $config->assignOption($this->thousand_separator, 'thousands_separator', 'numbers'); 126 $config->assignOption($this->fract_digits, 'fract_digits', 'numbers'); 127 $config->assignOption($this->negative_symbol, 'negative_symbol', 'numbers'); 128 $config->assignOption($this->positive_symbol, 'positive_symbol', 'numbers'); 129 130 $config->assignOption($this->currency_decimal_symbol, 'decimal_symbol', 'currency'); 131 $config->assignOption($this->currency_name, 'name', 'currency'); 132 $config->assignOption($this->currency_short_name, 'short_name', 'currency'); 133 $config->assignOption($this->currency_thousand_separator, 'thousands_separator', 'currency'); 134 $config->assignOption($this->currency_fract_digits, 'fract_digits', 'currency'); 135 $config->assignOption($this->currency_negative_symbol, 'negative_symbol', 'currency'); 136 $config->assignOption($this->currency_positive_symbol, 'positive_symbol', 'currency'); 137 $config->assignOption($this->currency_symbol, 'symbol', 'currency'); 138 $config->assignOption($this->currency_positive_format, 'positive_format', 'currency'); 139 $config->assignOption($this->currency_negative_format, 'negative_format', 'currency'); 140 } 141 142 protected function _initLanguageSettings($config) 143 { 144 $config->assignOption($this->language_name, 'language_name', 'regional_settings'); 145 $config->assignOption($this->intl_language_name, 'international_language_name', 'regional_settings'); 146 $config->assignOption($this->language_comment, 'language_comment', 'regional_settings'); 147 $config->assignOption($this->language_direction, 'language_direction', 'regional_settings'); 148 $config->assignOption($this->LC_ALL, 'LC_ALL', 'regional_settings'); 149 150 $charset = false; 151 if($config->hasOption('preferred', 'charset')) 152 { 153 $charset = $config->getOption('preferred', 'charset'); 154 if($charset != '') 155 $this->charset = $charset; 156 } 157 158 if(!is_array($this->short_day_names)) 159 $this->short_day_names = array(); 160 if(!is_array($this->long_day_names)) 161 $this->long_day_names = array(); 162 163 foreach ($this->week_days as $day) 164 { 165 if($config->hasOption($day, 'short_day_names')) 166 $this->short_day_names[$day] = $config->getOption($day, 'short_day_names'); 167 if($config->hasOption($day, 'long_day_names')) 168 $this->long_day_names[$day] = $config->getOption($day, 'long_day_names'); 169 } 170 171 if(!is_array($this->short_month_names)) 172 $this->short_month_names = array(); 173 if(!is_array($this->long_month_names)) 174 $this->long_month_names = array(); 175 176 foreach ($this->months as $month) 177 { 178 if($config->hasOption($month, 'short_month_names')) 179 $this->short_month_names[$month] = $config->getOption($month, 'short_month_names'); 180 if($config->hasOption($month, 'long_month_names')) 181 $this->long_month_names[$month] = $config->getOption($month, 'long_month_names'); 182 } 183 184 if(!is_array($this->short_day_names)) 185 $this->short_day_names = array(); 186 if(!is_array($this->long_day_names)) 187 $this->long_day_names = array(); 188 189 foreach($this->week_days as $wday) 190 { 191 if($config->hasOption($wday, 'short_day_names')) 192 $this->short_day_names[$wday] = $config->getOption($wday, 'short_day_names'); 193 if($config->hasOption($wday, 'long_day_names')) 194 $this->long_day_names[$wday] = $config->getOption($wday, 'long_day_names'); 195 } 196 } 197 198 function getLocaleSpec() 199 { 200 return $this->locale_spec; 201 } 202 203 function getLocaleString() 204 { 205 return $this->locale_spec->getLocaleString(); 206 } 207 208 function getLanguage() 209 { 210 return $this->locale_spec->getLanguage(); 211 } 212 213 function setPHPLocale() 214 { 215 setlocale(LC_ALL, $this->LC_ALL); 216 } 217 218 function getCharset() 219 { 220 return $this->charset; 221 } 222 223 function getLanguageDirection() 224 { 225 return $this->language_direction; 226 } 227 228 function getCountryName() 229 { 230 return $this->country; 231 } 232 233 function getCountryComment() 234 { 235 return $this->country_comment; 236 } 237 238 function getLanguageComment() 239 { 240 return $this->language_comment; 241 } 242 243 function getLanguageName() 244 { 245 return $this->language_name; 246 } 247 248 function getIntlLanguageName() 249 { 250 return $this->intl_language_name; 251 } 252 253 function getCurrencySymbol() 254 { 255 return $this->currency_symbol; 256 } 257 258 function getCurrencyName() 259 { 260 return $this->currency_name; 261 } 262 263 function getCurrencyShortName() 264 { 265 return $this->currency_short_name; 266 } 267 268 function getTimeFormat() 269 { 270 return $this->time_format; 271 } 272 273 function getShortTimeFormat() 274 { 275 return $this->short_time_format; 276 } 277 278 function getDateFormat() 279 { 280 return $this->date_format; 281 } 282 283 function getShortDateFormat() 284 { 285 return $this->short_date_format; 286 } 287 288 function getShortDateTimeFormat() 289 { 290 return $this->short_date_time_format; 291 } 292 293 function getShortDateShortTimeFormat() 294 { 295 return $this->short_date_short_time_format; 296 } 297 298 function getDateTimeFormat() 299 { 300 return $this->date_time_format; 301 } 302 303 function isMondayFirst() 304 { 305 return $this->is_monday_first; 306 } 307 308 function getWeekDays() 309 { 310 return $this->week_days; 311 } 312 313 function getMonths() 314 { 315 return $this->months; 316 } 317 318 function getWeekDayNames($short = false) 319 { 320 if($short) 321 return $this->short_day_names; 322 else 323 return $this->long_day_names; 324 } 325 326 function getMonthNames($short = false) 327 { 328 if($short) 329 return $this->short_month_names; 330 else 331 return $this->long_month_names; 332 } 333 334 function getMeridiemName($hour) 335 { 336 return ($hour < 12) ? $this->am_name : $this->pm_name; 337 } 338 339 function getPmName() 340 { 341 return $this->pm_name; 342 } 343 344 function getAmName() 345 { 346 return $this->am_name; 347 } 348 349 function getDayName($num, $short = false) 350 { 351 if($num < 0 || $num > 6) 352 return null; 353 354 if($short) 355 return $this->short_day_names[$num]; 356 else 357 return $this->long_day_names[$num]; 358 } 359 360 function getMonthName($num, $short = false) 361 { 362 if($num < 0 || $num > 11) 363 return null; 364 365 if($short) 366 return $this->short_month_names[$num]; 367 else 368 return $this->long_month_names[$num]; 369 } 370 } 371 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Oct 12 04:41:30 2008 | Cross-referenced by PHPXref 0.7 |