00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 include_once( 'lib/ezutils/classes/ezini.php' );
00131
00132 define( "EZ_LOCALE_DEBUG_INTERNALS", false );
00133
00134 class eZLocale
00135 {
00136
00137
00138
00139
00140 function eZLocale( $localeString )
00141 {
00142 $this->IsValid = false;
00143 $this->TimePHPArray = array( 'g', 'G', 'h', 'H', 'i', 's', 'U', 'I', 'L', 't' );
00144 $this->DatePHPArray = array( 'd', 'j', 'm', 'n', 'O', 'T', 'U', 'w', 'W', 'Y', 'y', 'z', 'Z', 'I', 'L', 't' );
00145 $this->DateTimePHPArray = array( 'd', 'j', 'm', 'n', 'O', 'T', 'U', 'w', 'W', 'Y', 'y', 'z', 'Z',
00146 'g', 'G', 'h', 'H', 'i', 's', 'U', 'I', 'L', 't', 'a' );
00147 $this->TimeArray = preg_replace( '/.+/', '%$0', $this->TimePHPArray );
00148 $this->DateArray = preg_replace( '/.+/', '%$0', $this->DatePHPArray );
00149 $this->DateTimeArray = preg_replace( '/.+/', '%$0', $this->DateTimePHPArray );
00150
00151 $this->TimeSlashInputArray = preg_replace( '/.+/', '/(?<!%)$0/', $this->TimePHPArray );
00152 $this->DateSlashInputArray = preg_replace( '/.+/', '/(?<!%)$0/', $this->DatePHPArray );
00153 $this->DateTimeSlashInputArray = preg_replace( '/.+/', '/(?<!%)$0/', $this->DateTimePHPArray );
00154
00155 $this->TimeSlashOutputArray = preg_replace( '/.+/', '\\\\$0', $this->TimePHPArray );
00156 $this->DateSlashOutputArray = preg_replace( '/.+/', '\\\\$0', $this->DatePHPArray );
00157 $this->DateTimeSlashOutputArray = preg_replace( '/.+/', '\\\\$0', $this->DateTimePHPArray );
00158
00159 $this->HTTPLocaleCode = '';
00160 $this->functionMap = array(
00161 'time' => 'formatTime',
00162 'shorttime' => 'formatShortTime',
00163 'date' => 'formatDate',
00164 'shortdate' => 'formatShortDate',
00165 'datetime' => 'formatDateTime',
00166 'shortdatetime' => 'formatShortDateTime',
00167 'currency' => 'formatCurrencyWithSymbol',
00168 'clean_currency' => 'formatCleanCurrency',
00169 'number' => 'formatNumber',
00170 );
00171
00172 $this->DayNames = array( 0 => 'sun', 1 => 'mon', 2 => 'tue',
00173 3 => 'wed', 4 => 'thu', 5 => 'fri', 6 => 'sat' );
00174 $this->MonthNames = array( 1 => 'jan', 2 => 'feb', 3 => 'mar',
00175 4 => 'apr', 5 => 'may', 6 => 'jun',
00176 7 => 'jul', 8 => 'aug', 9 => 'sep',
00177 10 => 'oct', 11 => 'nov', 12 => 'dec' );
00178 $this->WeekDays = array( 0, 1, 2, 3, 4, 5, 6 );
00179 $this->Months = array( 1, 2, 3, 4, 5, 6,
00180 7, 8, 9, 10, 11, 12 );
00181
00182 $locale = eZLocale::localeInformation( $localeString );
00183
00184 $this->CountryCode = $locale['country'];
00185 $this->CountryVariation = $locale['country-variation'];
00186 $this->LanguageCode = $locale['language'];
00187 $this->LocaleCode = $locale['locale'];
00188 $this->TranslationCode = $locale['locale'];
00189 $this->Charset = $locale['charset'];
00190 $this->OverrideCharset = $locale['charset'];
00191
00192 $this->LocaleINI = array( 'default' => null, 'variation' => null );
00193 $this->CountryINI = array( 'default' => null, 'variation' => null );
00194 $this->LanguageINI = array( 'default' => null, 'variation' => null );
00195
00196
00197 $localeINI =& $this->localeFile();
00198 $countryINI =& $localeINI;
00199 $languageINI =& $localeINI;
00200 if ( $localeINI === null )
00201 {
00202 $countryINI =& $this->countryFile();
00203 $languageINI =& $this->languageFile();
00204 }
00205
00206 $this->reset();
00207
00208 $this->IsValid = true;
00209
00210
00211 if ( $countryINI !== null )
00212 {
00213 $this->initCountry( $countryINI );
00214 }
00215 else
00216 {
00217 $this->IsValid = false;
00218 eZDebug::writeError( 'Could not load country settings for ' . $this->CountryCode, 'eZLocale' );
00219 }
00220
00221
00222 if ( $languageINI !== null )
00223 {
00224 $this->initLanguage( $languageINI );
00225 }
00226 else
00227 {
00228 $this->IsValid = false;
00229 eZDebug::writeError( 'Could not load language settings for ' . $this->LanguageCode, 'eZLocale' );
00230 }
00231
00232
00233
00234 if ( $this->countryVariation() )
00235 {
00236 $localeVariationINI =& $this->localeFile( true );
00237 $countryVariationINI = $localeVariationINI;
00238 $languageVariationINI = $localeVariationINI;
00239 if ( $localeVariationINI === null )
00240 {
00241 $countryVariationINI = $this->countryFile( true );
00242 $languageVariationINI = $this->languageFile( true );
00243 }
00244
00245
00246 if ( $countryVariationINI !== null )
00247 {
00248 $this->initCountry( $countryVariationINI );
00249 }
00250
00251
00252 if ( $languageVariationINI !== null )
00253 {
00254 $this->initLanguage( $languageVariationINI );
00255 }
00256 }
00257
00258 if ( $this->MondayFirst )
00259 {
00260 $this->WeekDays[] = array_shift( $this->WeekDays );
00261 }
00262
00263 $this->AM = 'am';
00264 $this->PM = 'pm';
00265 }
00266
00267
00268
00269
00270 function reset()
00271 {
00272 $this->TimeFormat = '';
00273 $this->ShortTimeFormat = '';
00274 $this->DateFormat = '';
00275 $this->ShortDateFormat = '';
00276 $this->DateTimeFormat = '';
00277 $this->ShortDateTimeFormat = '';
00278
00279 $this->MondayFirst = false;
00280
00281 $this->Country = '';
00282 $this->CountryComment = '';
00283
00284 $this->DecimalSymbol = '';
00285 $this->ThousandsSeparator = '';
00286 $this->FractDigits = 2;
00287 $this->NegativeSymbol = '-';
00288 $this->PositiveSymbol = '';
00289
00290 $this->CurrencyDecimalSymbol = '';
00291 $this->CurrencyName = '';
00292 $this->CurrencyShortName = '';
00293 $this->CurrencyThousandsSeparator = '';
00294 $this->CurrencyFractDigits = 2;
00295 $this->CurrencyNegativeSymbol = '-';
00296 $this->CurrencyPositiveSymbol = '';
00297 $this->CurrencySymbol = '';
00298 $this->CurrencyPositiveFormat = '';
00299 $this->CurrencyNegativeFormat = '';
00300 $this->CountryNames = '';
00301
00302 $this->LanguageName = '';
00303 $this->LanguageComment = '';
00304 $this->IntlLanguageName = '';
00305 $this->AllowedCharsets = array();
00306
00307 $this->ShortDayNames = array();
00308 $this->LongDayNames = array();
00309 foreach ( $this->DayNames as $day )
00310 {
00311 $this->ShortDayNames[$day] = '';
00312 $this->LongDayNames[$day] = '';
00313 }
00314
00315 $this->ShortMonthNames = array();
00316 $this->LongMonthNames = array();
00317 foreach ( $this->MonthNames as $month )
00318 {
00319 $this->ShortMonthNames[$month] = '';
00320 $this->LongMonthNames[$month] = '';
00321 }
00322
00323 $this->ShortWeekDayNames = array();
00324 $this->LongWeekDayNames = array();
00325 foreach( $this->WeekDays as $wday )
00326 {
00327 $code = $this->DayNames[$wday];
00328 $this->ShortWeekDayNames[$wday] = '';
00329 $this->LongWeekDayNames[$wday] = '';
00330 }
00331 }
00332
00333
00334
00335
00336 function isValid()
00337 {
00338 return $this->IsValid;
00339 }
00340
00341
00342
00343
00344 function initCountry( &$countryINI )
00345 {
00346 $countryINI->assign( 'DateTime', 'TimeFormat', $this->TimeFormat );
00347 $countryINI->assign( 'DateTime', 'ShortTimeFormat', $this->ShortTimeFormat );
00348 $countryINI->assign( 'DateTime', 'DateFormat', $this->DateFormat );
00349 $countryINI->assign( 'DateTime', 'ShortDateFormat', $this->ShortDateFormat );
00350 $countryINI->assign( 'DateTime', 'DateTimeFormat', $this->DateTimeFormat );
00351 $countryINI->assign( 'DateTime', 'ShortDateTimeFormat', $this->ShortDateTimeFormat );
00352
00353 if ( $countryINI->hasVariable( 'DateTime', 'MondayFirst' ) )
00354 $this->MondayFirst = strtolower( $countryINI->variable( 'DateTime', 'MondayFirst' ) ) == 'yes';
00355
00356 $countryINI->assign( 'RegionalSettings', 'Country', $this->Country );
00357 $countryINI->assign( "RegionalSettings", "CountryComment", $this->CountryComment );
00358
00359 $countryINI->assign( 'Numbers', 'DecimalSymbol', $this->DecimalSymbol );
00360 $countryINI->assign( 'Numbers', 'ThousandsSeparator', $this->ThousandsSeparator );
00361 $countryINI->assign( 'Numbers', 'FractDigits', $this->FractDigits );
00362 $countryINI->assign( 'Numbers', 'NegativeSymbol', $this->NegativeSymbol );
00363 $countryINI->assign( 'Numbers', 'PositiveSymbol', $this->PositiveSymbol );
00364
00365 $countryINI->assign( 'Currency', 'DecimalSymbol', $this->CurrencyDecimalSymbol );
00366 $countryINI->assign( 'Currency', 'Name', $this->CurrencyName );
00367 $countryINI->assign( 'Currency', 'ShortName', $this->CurrencyShortName );
00368 $countryINI->assign( 'Currency', 'ThousandsSeparator', $this->CurrencyThousandsSeparator );
00369 $countryINI->assign( 'Currency', 'FractDigits', $this->CurrencyFractDigits );
00370 $countryINI->assign( 'Currency', 'NegativeSymbol', $this->CurrencyNegativeSymbol );
00371 $countryINI->assign( 'Currency', 'PositiveSymbol', $this->CurrencyPositiveSymbol );
00372 $countryINI->assign( 'Currency', 'Symbol', $this->CurrencySymbol );
00373 $countryINI->assign( 'Currency', 'PositiveFormat', $this->CurrencyPositiveFormat );
00374 $countryINI->assign( 'Currency', 'NegativeFormat', $this->CurrencyNegativeFormat );
00375 if ( $countryINI->hasVariable( 'CountryNames', 'Countries' ) )
00376 $this->CountryNames = $countryINI->variable( 'CountryNames', 'Countries' );
00377
00378 }
00379
00380
00381
00382
00383 function initLanguage( &$languageINI )
00384 {
00385 $languageINI->assign( "RegionalSettings", "LanguageName", $this->LanguageName );
00386 $languageINI->assign( "RegionalSettings", "InternationalLanguageName", $this->IntlLanguageName );
00387 $languageINI->assign( "RegionalSettings", "LanguageComment", $this->LanguageComment );
00388 $languageINI->assign( 'RegionalSettings', 'TranslationCode', $this->TranslationCode );
00389
00390 if ( $this->OverrideCharset == '' )
00391 {
00392 $charset = false;
00393 if ( $languageINI->hasVariable( 'Charset', 'Preferred' ) )
00394 {
00395 $charset = $languageINI->variable( 'Charset', 'Preferred' );
00396 if ( $charset != '' )
00397 $this->Charset = $charset;
00398 }
00399 }
00400 if ( $languageINI->hasVariable( 'Charset', 'Allowed' ) )
00401 {
00402 $this->AllowedCharsets = $languageINI->variable( 'Charset', 'Allowed' );
00403 }
00404 else
00405 {
00406 if ( $languageINI->hasVariable( 'Charset', 'Preferred' ) )
00407 $this->AllowedCharsets[] = $languageINI->variable( 'Charset', 'Preferred' );
00408 }
00409
00410
00411 if ( !is_array( $this->ShortDayNames ) )
00412 $this->ShortDayNames = array();
00413 if ( !is_array( $this->LongDayNames ) )
00414 $this->LongDayNames = array();
00415
00416 $tmpShortDayNames = array();
00417 if ( $languageINI->hasGroup( 'ShortDayNames' ) )
00418 $tmpShortDayNames = $languageINI->variableMulti( 'ShortDayNames', $this->DayNames );
00419 $tmpLongDayNames = array();
00420 if ( $languageINI->hasGroup( 'LongDayNames' ) )
00421 $tmpLongDayNames = $languageINI->variableMulti( 'LongDayNames', $this->DayNames );
00422 foreach ( $this->DayNames as $key => $day )
00423 {
00424 if ( isset( $tmpShortDayNames[$key] ) )
00425 $this->ShortDayNames[$day] = $tmpShortDayNames[$key];
00426 if ( isset( $tmpLongDayNames[$key] ) )
00427 $this->LongDayNames[$day] = $tmpLongDayNames[$key];
00428 }
00429
00430
00431 if ( !is_array( $this->ShortMonthNames ) )
00432 $this->LongMonthNames = array();
00433 if ( !is_array( $this->ShortMonthNames ) )
00434 $this->LongMonthNames = array();
00435
00436 $tmpShortMonthNames = array();
00437 if ( $languageINI->hasGroup( 'ShortMonthNames' ) )
00438 $tmpShortMonthNames = $languageINI->variableMulti( 'ShortMonthNames', $this->MonthNames );
00439 $tmpLongMonthNames = array();
00440 if ( $languageINI->hasGroup( 'LongMonthNames' ) )
00441 $tmpLongMonthNames = $languageINI->variableMulti( 'LongMonthNames', $this->MonthNames );
00442 foreach ( $this->MonthNames as $key => $day )
00443 {
00444 if ( isset( $tmpShortMonthNames[$key] ) )
00445 $this->ShortMonthNames[$day] = $tmpShortMonthNames[$key];
00446 if ( isset( $tmpLongMonthNames[$key] ) )
00447 $this->LongMonthNames[$day] = $tmpLongMonthNames[$key];
00448 }
00449
00450
00451 if ( !is_array( $this->ShortWeekDayNames ) )
00452 $this->ShortWeekDayNames = array();
00453 if ( !is_array( $this->LongWeekDayNames ) )
00454 $this->LongWeekDayNames = array();
00455
00456 foreach ( $this->WeekDays as $key => $day )
00457 {
00458 if ( isset( $tmpShortDayNames[$key] ) )
00459 $this->ShortWeekDayNames[$day] = $tmpShortDayNames[$key];
00460 if ( isset( $tmpLongDayNames[$key] ) )
00461 $this->LongWeekDayNames[$day] = $tmpLongDayNames[$key];
00462 }
00463
00464 if ( $languageINI->hasVariable( 'HTTP', 'ContentLanguage' ) )
00465 $this->HTTPLocaleCode = $languageINI->variable( 'HTTP', 'ContentLanguage' );
00466 }
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482 function localeRegexp( $withVariations = true, $withCharset = true )
00483 {
00484 return "([a-zA-Z]+)([_-]([a-zA-Z]+))?" . ( $withCharset ? "(\.([a-zA-Z-]+))?" : '' ) . ( $withVariations ? "(@([a-zA-Z0-9]+))?" : '' );
00485 }
00486
00487
00488
00489
00490
00491
00492
00493 function localeInformation( $localeString )
00494 {
00495 $info = null;
00496 if ( preg_match( '/^([a-zA-Z]+)([_-]([a-zA-Z]+))?(\.([a-zA-Z-]+))?(@([a-zA-Z0-9]+))?/', $localeString, $regs ) )
00497 {
00498 $info = array();
00499 $language = strtolower( $regs[1] );
00500 $country = '';
00501 if ( isset( $regs[3] ) )
00502 $country = strtoupper( $regs[3] );
00503 $charset = '';
00504 if ( isset( $regs[5] ) )
00505 $charset = strtolower( $regs[5] );
00506 $countryVariation = '';
00507 if ( isset( $regs[7] ) )
00508 $countryVariation = strtolower( $regs[7] );
00509 $locale = $language;
00510 if ( $country !== '' )
00511 $locale .= '-' . $country;
00512 $info['language'] = $language;
00513 $info['country'] = $country;
00514 $info['country-variation'] = $countryVariation;
00515 $info['charset'] = $charset;
00516 $info['locale'] = $locale;
00517 }
00518 else
00519 {
00520 $info = array();
00521 $locale = strtolower( $localeString );
00522 $language = $locale;
00523 $info['language'] = $language;
00524 $info['country'] = '';
00525 $info['country-variation'] = '';
00526 $info['charset'] = '';
00527 $info['locale'] = $locale;
00528 }
00529 return $info;
00530 }
00531
00532
00533
00534
00535
00536
00537 function initPHP( $charset = false )
00538 {
00539 if ( $charset === false )
00540 $charset = $this->Language->code();
00541 setlocale( LC_ALL, $charset );
00542 }
00543
00544 function attributes()
00545 {
00546 return array_keys( eZLocale::attributeFunctionMap() );
00547 }
00548
00549 function hasAttribute( $attribute )
00550 {
00551 $attributeMap = eZLocale::attributeFunctionMap();
00552 if ( isset( $attributeMap[$attribute] ) )
00553 return true;
00554 else
00555 return false;
00556 }
00557
00558 function &attribute( $attribute )
00559 {
00560 $attributeMap = eZLocale::attributeFunctionMap();
00561 if ( isset( $attributeMap[$attribute] ) )
00562 {
00563 $method = $attributeMap[$attribute];
00564 if ( method_exists( $this, $method ) )
00565 {
00566 $retValue = $this->$method();
00567 }
00568 else
00569 {
00570 eZDebug::writeError( "Unknown method '$method' specified for attribute '$attribute'", 'eZLocale::attribute' );
00571 $retValue = null;
00572 }
00573 }
00574 else
00575 {
00576 eZDebug::writeError( "Attribute '$attribute' does not exist", 'eZLocale::attribute' );
00577 $retValue = null;
00578 }
00579 return $retValue;
00580 }
00581
00582 function attributeFunctionMap()
00583 {
00584 return array( 'charset' => 'charset',
00585 'allowed_charsets' => 'allowedCharsets',
00586 'country_name' => 'countryName',
00587 'country_comment' => 'countryComment',
00588 'country_code' => 'countryCode',
00589 'country_variation' => 'countryVariation',
00590 'language_name' => 'languageName',
00591 'intl_language_name' => 'internationalLanguageName',
00592 'language_code' => 'languageCode',
00593 'language_comment' => 'languageComment',
00594 'locale_code' => 'localeCode',
00595 'locale_full_code' => 'localeFullCode',
00596 'http_locale_code' => 'httpLocaleCode',
00597 'decimal_symbol' => 'decimalSymbol',
00598 'thousands_separator' => 'thousandsSeparator',
00599 'decimal_count' => 'decimalCount',
00600 'negative_symbol' => 'negativeSymbol',
00601 'positive_symbol' => 'positiveSymbol',
00602 'currency_decimal_symbol' => 'currencyDecimalSymbol',
00603 'currency_thousands_separator' => 'currencyThousandsSeparator',
00604 'currency_decimal_count' => 'currencyDecimalCount',
00605 'currency_negative_symbol' => 'currencyNegativeSymbol',
00606 'currency_positive_symbol' => 'currencyPositiveSymbol',
00607 'currency_symbol' => 'currencySymbol',
00608 'currency_name' => 'currencyName',
00609 'currency_short_name' => 'currencyShortName',
00610 'is_monday_first' => 'isMondayFirst',
00611 'weekday_name_list' => 'weekDayNames',
00612 'weekday_short_name_list' => 'weekDayShortNames',
00613 'weekday_number_list' => 'weekDays',
00614 'month_list' => 'months',
00615 'month_name_list' => 'monthsNames',
00616 'is_valid' => 'isValid' );
00617 }
00618
00619
00620
00621
00622
00623 function charset()
00624 {
00625 return $this->Charset;
00626 }
00627
00628
00629
00630
00631 function allowedCharsets()
00632 {
00633 return $this->AllowedCharsets;
00634 }
00635
00636
00637
00638
00639 function countryName()
00640 {
00641 return $this->Country;
00642 }
00643
00644
00645
00646
00647 function countryComment()
00648 {
00649 return $this->CountryComment;
00650 }
00651
00652
00653
00654
00655 function countryCode()
00656 {
00657 return $this->CountryCode;
00658 }
00659
00660
00661
00662
00663 function countryVariation()
00664 {
00665 return $this->CountryVariation;
00666 }
00667
00668
00669
00670
00671 function languageCode()
00672 {
00673 return $this->LanguageCode;
00674 }
00675
00676
00677
00678
00679 function languageComment()
00680 {
00681 return $this->LanguageComment;
00682 }
00683
00684
00685
00686
00687
00688
00689
00690 function translationCode()
00691 {
00692 return $this->TranslationCode;
00693 }
00694
00695
00696
00697
00698
00699 function localeCode()
00700 {
00701 return $this->LocaleCode;
00702 }
00703
00704
00705
00706
00707 function localeFullCode()
00708 {
00709 $locale = $this->LocaleCode;
00710 $variation = $this->countryVariation();
00711 if ( $variation )
00712 $locale .= "@" . $variation;
00713 return $locale;
00714 }
00715
00716
00717
00718
00719
00720
00721
00722 function httpLocaleCode()
00723 {
00724 $ini =& eZINI::instance();
00725 $localeCode = '';
00726 if ( $ini->hasVariable( 'RegionalSettings', 'HTTPLocale' ) )
00727 {
00728 $localeCode = $ini->variable( 'RegionalSettings', 'HTTPLocale' );
00729 }
00730 if ( $localeCode == '' and
00731 $this->HTTPLocaleCode != '' )
00732 $localeCode = $this->HTTPLocaleCode;
00733 if ( $localeCode == '' )
00734 $localeCode = $this->localeCode();
00735 return $localeCode;
00736 }
00737
00738
00739
00740
00741
00742
00743
00744 function currentLocaleCode()
00745 {
00746 $locale =& eZLocale::instance();
00747 return $locale->localeCode();
00748 }
00749
00750
00751
00752
00753 function languageName()
00754 {
00755 return $this->LanguageName;
00756 }
00757
00758
00759
00760
00761 function internationalLanguageName()
00762 {
00763 return $this->IntlLanguageName;
00764 }
00765
00766
00767
00768
00769 function currencySymbol()
00770 {
00771 return $this->CurrencySymbol;
00772 }
00773
00774
00775
00776
00777 function currencyName()
00778 {
00779 return $this->CurrencyName;
00780 }
00781
00782
00783
00784
00785 function currencyShortName()
00786 {
00787 return $this->CurrencyShortName;
00788 }
00789
00790
00791
00792
00793
00794 function isMondayFirst()
00795 {
00796 return $this->MondayFirst;
00797 }
00798
00799
00800
00801
00802 function decimalSymbol()
00803 {
00804 return $this->DecimalSymbol;
00805 }
00806
00807
00808
00809
00810 function thousandsSeparator()
00811 {
00812 return $this->ThousandsSeparator;
00813 }
00814
00815
00816
00817
00818 function decimalCount()
00819 {
00820 return $this->FractDigits;
00821 }
00822
00823
00824
00825
00826 function negativeSymbol()
00827 {
00828 return $this->NegativeSymbol;
00829 }
00830
00831
00832
00833
00834 function positiveSymbol()
00835 {
00836 return $this->PositiveSymbol;
00837 }
00838
00839
00840
00841
00842 function currencyDecimalSymbol()
00843 {
00844 return $this->CurrencyDecimalSymbol;
00845 }
00846
00847
00848
00849
00850 function currencyThousandsSeparator()
00851 {
00852 return $this->CurrencyThousandsSeparator;
00853 }
00854
00855
00856
00857
00858 function currencyDecimalCount()
00859 {
00860 return $this->CurrencyFractDigits;
00861 }
00862
00863
00864
00865
00866 function currencyNegativeSymbol()
00867 {
00868 return $this->CurrencyNegativeSymbol;
00869 }
00870
00871
00872
00873
00874 function currencyPositiveSymbol()
00875 {
00876 return $this->CurrencyPositiveSymbol;
00877 }
00878
00879
00880
00881
00882
00883
00884 function weekDays()
00885 {
00886 return $this->WeekDays;
00887 }
00888
00889
00890
00891
00892
00893 function months()
00894 {
00895 return $this->Months;
00896 }
00897
00898
00899
00900
00901
00902 function monthsNames()
00903 {
00904 return $this->LongMonthNames;
00905 }
00906
00907
00908
00909
00910 function weekDayNames( $short = false )
00911 {
00912 if ( $short )
00913 $dayList = $this->ShortWeekDayNames;
00914 else
00915 $dayList = $this->LongWeekDayNames;
00916
00917 $resultDayList = array();
00918 foreach ( $this->WeekDays as $day )
00919 {
00920 $resultDayList[ $day ] = $dayList[ $day ];
00921 }
00922 return $resultDayList;
00923 }
00924
00925
00926
00927
00928 function weekDayShortNames()
00929 {
00930 return $this->weekDayNames( true );
00931 }
00932
00933
00934
00935
00936 function getFormattingFunction( $qualifier )
00937 {
00938 if ( isset( $this->functionMap[$qualifier] ) )
00939 {
00940 return $this->functionMap[$qualifier];
00941 }
00942 else
00943 {
00944 return false;
00945 }
00946 }
00947
00948
00949
00950
00951
00952 function formatTime( $time = false )
00953 {
00954 return $this->formatTimeType( $this->TimeFormat, $time );
00955 }
00956
00957
00958
00959
00960
00961 function formatShortTime( $time = false )
00962 {
00963 return $this->formatTimeType( $this->ShortTimeFormat, $time );
00964 }
00965
00966
00967
00968
00969
00970
00971 function formatTimeType( $fmt, $time = false )
00972 {
00973 if ( $time == false )
00974 $time = time();
00975
00976 $text = date( eZLocale::transformToPHPFormat( $fmt, $this->TimePHPArray ), $time );
00977 return str_replace( array( '%a', '%A' ),
00978 array( $this->meridiemName( $time, false ),
00979 $this->meridiemName( $time, true ) ),
00980 $text );
00981 }
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991 function meridiemName( $time = false, $upcase = false )
00992 {
00993 if ( $time == false )
00994 $time = mktime();
00995 $hour = date( 'G', $time );
00996 $name = $hour < 12 ? $this->AM : $this->PM;
00997 if ( $upcase )
00998 $name = strtoupper( $name );
00999 return $name;
01000 }
01001
01002
01003
01004
01005
01006 function formatDate( $date = false )
01007 {
01008 return $this->formatDateType( $this->DateFormat, $date );
01009 }
01010
01011
01012
01013
01014
01015 function formatShortDate( $date = false )
01016 {
01017 return $this->formatDateType( $this->ShortDateFormat, $date );
01018 }
01019
01020
01021
01022
01023
01024 function formatDateTime( $date = false )
01025 {
01026 return $this->formatDateTimeType( $this->DateTimeFormat, $date );
01027 }
01028
01029
01030
01031
01032
01033 function formatShortDateTime( $date = false )
01034 {
01035 return $this->formatDateTimeType( $this->ShortDateTimeFormat, $date );
01036 }
01037
01038
01039
01040
01041
01042
01043 function formatDateType( $fmt, $date = false )
01044 {
01045 if ( $date === false )
01046 $date = time();
01047
01048 $text = date( eZLocale::transformToPHPFormat( $fmt, $this->DatePHPArray ), $date );
01049 return str_replace( array( '%D', '%l', '%M', '%F' ),
01050 array( $this->shortDayName( date( 'w', $date ) ),
01051 $this->longDayName( date( 'w', $date ) ),
01052 $this->shortMonthName( date( 'n', $date ) ),
01053 $this->longMonthName( date( 'n', $date ) ) ),
01054 $text );
01055 }
01056
01057
01058
01059
01060
01061
01062 function formatDateTimeType( $fmt, $datetime = false )
01063 {
01064 if ( $datetime === false )
01065 $datetime = time();
01066
01067 $text = date( eZLocale::transformToPHPFormat( $fmt, $this->DateTimePHPArray ), $datetime );
01068
01069
01070 return str_replace( array( '%D', '%l', '%M', '%F',
01071 '%a', '%A' ),
01072 array( $this->shortDayName( date( 'w', $datetime ) ),
01073 $this->longDayName( date( 'w', $datetime ) ),
01074 $this->shortMonthName( date( 'n', $datetime ) ),
01075 $this->longMonthName( date( 'n', $datetime ) ),
01076 $this->meridiemName( $datetime, false ),
01077 $this->meridiemName( $datetime, true ) ),
01078 $text );
01079 }
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091 function transformToPHPFormat( $fmt, $allowed )
01092 {
01093
01094
01095
01096
01097
01098
01099 $dateFmt = '';
01100 $offs = 0;
01101 $len = strlen( $fmt );
01102 while ( $offs < $len )
01103 {
01104 $char = $fmt[$offs];
01105 if ( $char == '%' )
01106 {
01107 if ( $offs + 1 < $len )
01108 {
01109 $type = $fmt[$offs + 1];
01110 if ( $type == '%' )
01111 {
01112 $dateFmt .= '%';
01113 }
01114 else if ( ( $type >= 'a' and $type <= 'z' ) or
01115 ( $type >= 'A' and $type <= 'Z' ) )
01116 {
01117
01118
01119 if ( !in_array( $type, $allowed ) )
01120 $dateFmt .= '%\\';
01121 $dateFmt .= $type;
01122 }
01123 else
01124 {
01125 $dateFmt .= $char . $type;
01126 }
01127 $offs += 2;
01128 }
01129 else
01130 {
01131 $dateFmt .= '\\' . $char;
01132 ++$offs;
01133 }
01134 }
01135 else
01136 {
01137
01138 if ( ( $char >= 'a' and $char <= 'z' ) or
01139 ( $char >= 'A' and $char <= 'Z' ) )
01140 $dateFmt .= '\\';
01141 $dateFmt .= $char;
01142 ++$offs;
01143 }
01144 }
01145 return $dateFmt;
01146 }
01147
01148
01149
01150
01151 function formatNumber( $number )
01152 {
01153 $neg = $number < 0;
01154 $num = $neg ? -$number : $number;
01155 $text = number_format( $num, $this->FractDigits, $this->DecimalSymbol, $this->ThousandsSeparator );
01156 return ( $neg ? $this->NegativeSymbol : $this->PositiveSymbol ) . $text;
01157 }
01158
01159
01160
01161
01162 function internalNumber( $number )
01163 {
01164 if ( preg_match( '/^(['.$this->PositiveSymbol.']|['.$this->NegativeSymbol.'])?([0-9]*|[0-9]{1,3}(['.$this->ThousandsSeparator.'][0-9]{3,3})*)(['.$this->DecimalSymbol.'][0-9]+)?$/', trim( $number ) ) )
01165 {
01166 $number = str_replace( ' ', '', $number );
01167 if ( $this->PositiveSymbol )
01168 $number = str_replace( $this->PositiveSymbol, '', $number );
01169 $number = str_replace( $this->NegativeSymbol, '-', $number );
01170 $number = str_replace( $this->ThousandsSeparator, '', $number );
01171 $number = str_replace( $this->DecimalSymbol, '.', $number );
01172 }
01173 return $number;
01174 }
01175
01176
01177
01178
01179
01180
01181 function formatCurrency( $number, $as_html = true )
01182 {
01183 return $this->formatCurrencyWithSymbol( $number, $this->CurrencySymbol );
01184 }
01185
01186
01187
01188
01189
01190
01191 function formatCleanCurrency( $number )
01192 {
01193 $text = $this->formatCurrencyWithSymbol( $number, '', true );
01194 return trim( $text );
01195 }
01196
01197 function formatCurrencyWithSymbol( $number, $symbol )
01198 {
01199 $neg = $number < 0;
01200 $num = $neg ? -$number : $number;
01201 $num_text = number_format( $num, $this->CurrencyFractDigits,
01202 $this->CurrencyDecimalSymbol, $this->CurrencyThousandsSeparator );
01203 return str_replace( array( '%c', '%p', '%q' ),
01204 array( $symbol,
01205 $neg ? $this->CurrencyNegativeSymbol : $this->CurrencyPositiveSymbol,
01206 $num_text ),
01207 $neg ? $this->CurrencyNegativeFormat : $this->CurrencyPositiveFormat );
01208 }
01209
01210 function translatedCountryNames()
01211 {
01212 return $this->CountryNames;
01213 }
01214
01215
01216
01217
01218 function internalCurrency( $number )
01219 {
01220 if ( preg_match( '/^(['.$this->CurrencyPositiveSymbol.']|['.$this->CurrencyNegativeSymbol.'])?([0-9]*|[0-9]{1,3}(['.$this->ThousandsSeparator.'][0-9]{3,3})*)(['.$this->CurrencyDecimalSymbol.'][0-9]+)?$/', trim( $number ) ) )
01221 {
01222 $number = str_replace( ' ', '', $number );
01223 if ( $this->CurrencyPositiveSymbol )
01224 $number = str_replace( $this->CurrencyPositiveSymbol, '', $number );
01225 $number = str_replace( $this->CurrencyNegativeSymbol, '-', $number );
01226 $number = str_replace( $this->CurrencyThousandsSeparator, '', $number );
01227 $number = str_replace( $this->CurrencyDecimalSymbol, '.', $number );
01228 }
01229 return $number;
01230 }
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244
01245 function shortDayName( $num )
01246 {
01247 if ( $num >= 0 and $num <= 6 )
01248 {
01249 $code = $this->DayNames[$num];
01250 $name = $this->ShortDayNames[$code];
01251 }
01252 else
01253 {
01254 $name = null;
01255 }
01256 return $name;
01257 }
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272 function longDayName( $num )
01273 {
01274 if ( $num >= 0 and $num <= 6 )
01275 {
01276 $code = $this->DayNames[$num];
01277 $name = $this->LongDayNames[$code];
01278 }
01279 else
01280 {
01281 $name = null;
01282 }
01283 return $name;
01284 }
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304 function shortMonthName( $num )
01305 {
01306 if ( $num >= 1 and $num <= 12 )
01307 {
01308 $code = $this->MonthNames[$num];
01309 $name = $this->ShortMonthNames[$code];
01310 }
01311 else
01312 {
01313 $name = null;
01314 }
01315 return $name;
01316 }
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336 function longMonthName( $num )
01337 {
01338 if ( $num >= 1 and $num <= 12 )
01339 {
01340 $code = $this->MonthNames[$num];
01341 $name = $this->LongMonthNames[$code];
01342 }
01343 else
01344 {
01345 $name = null;
01346 }
01347 return $name;
01348 }
01349
01350
01351
01352
01353
01354
01355
01356 function localeList( $asObject = false, $withVariations = true )
01357 {
01358 $locales =& $GLOBALS['eZLocaleLocaleStringList'];
01359 if ( !is_array( $locales ) )
01360 {
01361 $localeRegexp = eZLocale::localeRegexp( $withVariations, false );
01362 $locales = array();
01363 $dir = opendir( 'share/locale' );
01364 while( ( $file = readdir( $dir ) ) !== false )
01365 {
01366 if ( preg_match( "/^($localeRegexp)\.ini$/", $file, $regs ) )
01367 {
01368 $locales[] = $regs[1];
01369 }
01370 }
01371 closedir( $dir );
01372 $locales = array_unique( $locales );
01373 sort( $locales );
01374 if ( $asObject )
01375 {
01376 $localeObjects = array();
01377 foreach ( $locales as $locale )
01378 {
01379 $localeInstance =& eZLocale::instance( $locale );
01380 if ( $localeInstance )
01381 $localeObjects[] = $localeInstance;
01382 }
01383 $locales = $localeObjects;
01384 }
01385 }
01386 return $locales;
01387 }
01388
01389
01390
01391
01392
01393
01394
01395 function countryList( $withVariations = true )
01396 {
01397 $countries =& $GLOBALS['eZLocaleCountryList'];
01398 if ( !is_array( $countries ) )
01399 {
01400 $localeRegexp = eZLocale::localeRegexp( $withVariations, false );
01401 $countries = array();
01402 $dir = opendir( 'share/locale' );
01403 while( ( $file = readdir( $dir ) ) !== false )
01404 {
01405 if ( preg_match( "/^$localeRegexp\.ini$/", $file, $regs ) )
01406 {
01407 $countries[] = $regs[3];
01408 }
01409 }
01410 closedir( $dir );
01411 sort( array_unique( $countries ) );
01412 }
01413 return $countries;
01414 }
01415
01416
01417
01418
01419
01420
01421
01422 function languageList( $withVariations = true )
01423 {
01424 $languages =& $GLOBALS['eZLocaleLanguageist'];
01425 if ( !is_array( $languages ) )
01426 {
01427 $localeRegexp = eZLocale::localeRegexp( $withVariations, false );
01428 $languages = array();
01429 $dir = opendir( 'share/locale' );
01430 while( ( $file = readdir( $dir ) ) !== false )
01431 {
01432 if ( preg_match( "/^$localeRegexp\.ini$/", $file, $regs ) )
01433 {
01434 $languages[] = $regs[1];
01435 }
01436 }
01437 closedir( $dir );
01438 sort( array_unique( $languages ) );
01439 }
01440 return $languages;
01441 }
01442
01443
01444
01445
01446
01447
01448 function &localeFile( $withVariation = false )
01449 {
01450 $type = $withVariation ? 'variation' : 'default';
01451 if ( get_class( $this->LocaleINI[$type] ) != 'ezini' )
01452 {
01453 $country = $this->countryCode();
01454 $countryVariation = $this->countryVariation();
01455 $language = $this->languageCode();
01456 $locale = $language;
01457 if ( $country !== '' )
01458 $locale .= '-' . $country;
01459 if ( $withVariation )
01460 {
01461 if ( $countryVariation !== '' )
01462 $locale .= '@' . $countryVariation;
01463 }
01464 $localeFile = $locale . '.ini';
01465 if ( eZLocale::isDebugEnabled() )
01466 eZDebug::writeNotice( "Requesting $localeFile", 'eZLocale::localeFile' );
01467 if ( eZINI::exists( $localeFile, 'share/locale' ) )
01468 $this->LocaleINI[$type] = eZINI::instance( $localeFile, 'share/locale' );
01469 }
01470 return $this->LocaleINI[$type];
01471 }
01472
01473
01474
01475
01476
01477 function &countryFile( $withVariation = false )
01478 {
01479 $type = $withVariation ? 'variation' : 'default';
01480 if ( get_class( $this->CountryINI[$type] ) != 'ezini' )
01481 {
01482 $country = $this->countryCode();
01483 $countryVariation = $this->countryVariation();
01484 $locale = $country;
01485 if ( $withVariation )
01486 {
01487 if ( $countryVariation !== '' )
01488 $locale .= '@' . $countryVariation;
01489 }
01490 $countryFile = 'country/' . $locale . '.ini';
01491 if ( eZLocale::isDebugEnabled() )
01492 eZDebug::writeNotice( "Requesting $countryFile", 'eZLocale::countryFile' );
01493 if ( eZINI::exists( $countryFile, 'share/locale' ) )
01494 $this->CountryINI[$type] = eZINI::instance( $countryFile, 'share/locale' );
01495 }
01496 return $this->CountryINI[$type];
01497 }
01498
01499
01500
01501
01502
01503 function &languageFile( $withVariation = false )
01504 {
01505 $type = $withVariation ? 'variation' : 'default';
01506 if ( get_class( $this->LanguageINI[$type] ) != 'ezini' )
01507 {
01508 $language = $this->languageCode();
01509 $countryVariation = $this->countryVariation();
01510 $locale = $language;
01511 if ( $withVariation )
01512 {
01513 if ( $countryVariation !== '' )
01514 $locale .= '@' . $countryVariation;
01515 }
01516 $languageFile = 'language/' . $locale . '.ini';
01517 if ( eZLocale::isDebugEnabled() )
01518 eZDebug::writeNotice( "Requesting $languageFile", 'eZLocale::languageFile' );
01519 if ( eZINI::exists( $languageFile, 'share/locale' ) )
01520 $this->LanguageINI[$type] = eZINI::instance( $languageFile, 'share/locale' );
01521 }
01522 return $this->LanguageINI[$type];
01523 }
01524
01525
01526
01527
01528
01529
01530
01531
01532 function &instance( $localeString = false )
01533 {
01534 if ( $localeString === false )
01535 {
01536 $localeStringDefault =& $GLOBALS["eZLocaleStringDefault"];
01537 if (!isset( $localeStringDefault ) )
01538 {
01539 $ini =& eZINI::instance();
01540 $localeString = $ini->variable( 'RegionalSettings', 'Locale' );
01541
01542
01543 $localeStringDefault = $localeString;
01544 }
01545 else
01546 {
01547
01548 $localeString = $localeStringDefault;
01549 }
01550 }
01551 $instance =& $GLOBALS["eZLocaleInstance_$localeString"];
01552 if ( get_class( $instance ) != 'ezlocale' )
01553 {
01554 $instance = new eZLocale( $localeString );
01555 }
01556 return $instance;
01557 }
01558
01559
01560
01561
01562
01563 function create( $localeString = false )
01564 {
01565 if ( $localeString === false )
01566 {
01567 $ini =& eZINI::instance();
01568 $localeString = $ini->variable( 'RegionalSettings', 'Locale' );
01569 }
01570 return new eZLocale( $localeString );
01571 }
01572
01573
01574
01575
01576
01577
01578
01579 function isDebugEnabled()
01580 {
01581 if ( !isset( $GLOBALS['eZLocaleDebugInternalsEnabled'] ) )
01582 $GLOBALS['eZLocaleDebugInternalsEnabled'] = EZ_LOCALE_DEBUG_INTERNALS;
01583 return $GLOBALS['eZLocaleDebugInternalsEnabled'];
01584 }
01585
01586
01587
01588
01589
01590 function setIsDebugEnabled( $debug )
01591 {
01592 $GLOBALS['eZLocaleDebugInternalsEnabled'] = $debug;
01593 }
01594
01595
01596
01597
01598 function resetGlobals( $localeString = false )
01599 {
01600 if ( $localeString === false )
01601 {
01602 $localeStringDefault =& $GLOBALS["eZLocaleStringDefault"];
01603 if ( isset( $localeStringDefault ) )
01604 {
01605 $localeString = $localeStringDefault;
01606 }
01607 }
01608
01609 unset( $GLOBALS["eZLocaleInstance_$localeString"] );
01610 unset( $GLOBALS["eZLocaleStringDefault"] );
01611 }
01612
01613
01614 var $IsValid;
01615
01616
01617
01618
01619 var $DateFormat;
01620
01621 var $ShortDateFormat;
01622
01623 var $TimeFormat;
01624
01625 var $ShortTimeFormat;
01626
01627 var $MondayFirst;
01628
01629 var $AM, $PM;
01630
01631
01632
01633
01634 var $DecimalSymbol;
01635 var $ThousandsSeparator;
01636 var $FractDigits;
01637 var $NegativeSymbol;
01638 var $PositiveSymbol;
01639
01640
01641
01642
01643 var $CurrencyDecimalSymbol;
01644 var $CurrencyThousandsSeparator;
01645 var $CurrencyFractDigits;
01646 var $CurrencyNegativeSymbol;
01647 var $CurrencyPositiveSymbol;
01648 var $CurrencySymbol;
01649 var $CurrencyPositiveFormat;
01650 var $CurrencyNegativeFormat;
01651
01652
01653
01654
01655 var $DayNames;
01656 var $ShortDayNames, $LongDayNames;
01657 var $MonthNames;
01658 var $ShortMonthNames, $LongMonthNames;
01659 var $WeekDays, $Months;
01660 var $ShortWeekDayNames, $LongWeekDayNames;
01661
01662 var $TimeArray;
01663 var $DateArray;
01664 var $TimePHPArray;
01665 var $DatePHPArray;
01666
01667
01668
01669
01670 var $Country;
01671 var $CountryCode;
01672 var $CountryVariation;
01673 var $CountryComment;
01674 var $LanguageComment;
01675 var $LocaleINI;
01676 var $CountryINI;
01677 var $LanguageINI;
01678
01679 var $LanguageCode;
01680
01681 var $LanguageName;
01682
01683 var $IntlLanguageName;
01684 var $CountryNames;
01685
01686 };
01687
01688 ?>