[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/ezlocale/classes/ -> ezlocale.php (source)

   1  <?php
   2  //
   3  // Definition of eZLocale class
   4  //
   5  // Created on: <01-Mar-2002 13:48:32 amos>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*! \defgroup eZLocale Locale system */
  30  
  31  /*!
  32    \class eZLocale ezlocale.php
  33    \ingroup eZLocale
  34    \brief Provides unified access to locale information and conversions.
  35  
  36    The eZLocale class handles locale information and can format time, date, numbers and currency
  37    for correct display for a given locale. The locale conversion uses plain numerical values for
  38    dates, times, numbers and currency, if you want more elaborate conversions consider using the
  39    eZDate, eZTime, eZDateTime and eZCurrency classes.
  40  
  41    The first time a locale object is created (ie. eZLocale::instance() ) you must be sure to set
  42    a language using setLanguage before using any textual conversions.
  43  
  44    Example:
  45  
  46  \code
  47  include_once( 'lib/ezlocale/classes/ezlocale.php' );
  48  
  49  // Fetch the default values supplied by site.ini
  50  $locale =& eZLocale::instance();
  51  
  52  // Make sure PHP is to the correct locale
  53  $locale->initPHP();
  54  
  55  print( $locale->formatTime() . '<br>' ); // Display current time
  56  print( $locale->formatDate() . '<br>' ); // Display current day
  57  
  58  foreach ( $locale->weekDays() as $day ) // Print a week with 3 letter daynames
  59  {
  60      print( $locale->shortDayName( $day ) . '<br>' );
  61  }
  62  \endcode
  63  
  64  Countries are specified by the ISO 3166 Country Code
  65  http://www.iso.ch/iso/en/prods-services/iso3166ma/index.html
  66  User-assigned code elements
  67  http://www.iso.ch/iso/en/prods-services/iso3166ma/04background-on-iso-3166/reserved-and-user-assigned-codes.html#userassigned
  68  
  69  
  70  Language is specified by the ISO 639 Language Code
  71  http://www.w3.org/WAI/ER/IG/ert/iso639.htm
  72  
  73  Currency/funds are specified by the ISO 4217
  74  http://www.bsi-global.com/Technical+Information/Publications/_Publications/tig90.xalter
  75  
  76  
  77  Discussion on Norwegian locales
  78  https://lister.ping.uio.no/pipermail/lister.ping.uio.no/i18n-nn/2002-April.txt
  79  http://www.sprakrad.no/oss.htm
  80  
  81  
  82  The date and time formats are quite similar to the builting PHP date function,
  83  the main differences are those which returns textual representations of months
  84  and days.
  85  More info on the date function here:
  86  http://www.php.net/manual/en/function.date.php
  87  
  88  The following characters are not recognized in the format string:
  89  
  90  - B - Swatch Internet time
  91  - r - RFC 822 formatted date; e.g. "Thu, 21 Dec 2000 16:01:07 +0200" (added in PHP 4.0.4)
  92  - S - English ordinal suffix for the day of the month, 2 characters; i.e. "st", "nd", "rd" or "th"
  93  
  94  The following characters are recognized in the format string:
  95  
  96  - a - "am" or "pm"
  97  - A - "AM" or "PM"
  98  - d - day of the month, 2 digits with leading zeros; i.e. "01" to "31"
  99  - D - day of the week, textual, 3 letters; e.g. "Fri"
 100  - F - month, textual, long; e.g. "January"
 101  - g - hour, 12-hour format without leading zeros; i.e. "1" to "12"
 102  - G - hour, 24-hour format without leading zeros; i.e. "0" to "23"
 103  - h - hour, 12-hour format; i.e. "01" to "12"
 104  - H - hour, 24-hour format; i.e. "00" to "23"
 105  - i - minutes; i.e. "00" to "59"
 106  - I (capital i) - "1" if Daylight Savings Time, "0" otherwise.
 107  - j - day of the month without leading zeros; i.e. "1" to "31"
 108  - l (lowercase 'L') - day of the week, textual, long; e.g. "Friday"
 109  - L - boolean for whether it is a leap year; i.e. "0" or "1"
 110  - m - month; i.e. "01" to "12"
 111  - M - month, textual, 3 letters; e.g. "Jan"
 112  - n - month without leading zeros; i.e. "1" to "12"
 113  - O - Difference to Greenwich time in hours; e.g. "+0200"
 114  - s - seconds; i.e. "00" to "59"
 115  - t - number of days in the given month; i.e. "28" to "31"
 116  - T - Timezone setting of this machine; e.g. "EST" or "MDT"
 117  - U - seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
 118  - w - day of the week, numeric, i.e. "0" (Sunday) to "6" (Saturday)
 119  - W - ISO-8601 week number of year, weeks starting on Monday (added in PHP 4.1.0)
 120  - Y - year, 4 digits; e.g. "1999"
 121  - y - year, 2 digits; e.g. "99"
 122  - z - day of the year; i.e. "0" to "365"
 123  - Z - timezone offset in seconds (i.e. "-43200" to "43200"). The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.
 124  
 125  \sa eZLanguage
 126  */
 127  
 128  include_once ( 'lib/ezutils/classes/ezini.php' );
 129  
 130  define( "EZ_LOCALE_DEBUG_INTERNALS", false );
 131  
 132  class eZLocale
 133  {
 134      /*!
 135       Initializes the locale with the locale string \a $localeString.
 136       All locale data is read from locale/$localeString.ini
 137      */
 138      function eZLocale( $localeString )
 139      {
 140          $this->IsValid = false;
 141          $this->TimePHPArray = array( 'g', 'G', 'h', 'H', 'i', 's', 'U', 'I', 'L', 't' );
 142          $this->DatePHPArray = array( 'd', 'j', 'm', 'n', 'O', 'T', 'U', 'w', 'W', 'Y', 'y', 'z', 'Z', 'I', 'L', 't' );
 143          $this->DateTimePHPArray = array( 'd', 'j', 'm', 'n', 'O', 'T', 'U', 'w', 'W', 'Y', 'y', 'z', 'Z',
 144                                           'g', 'G', 'h', 'H', 'i', 's', 'U', 'I', 'L', 't', 'a' );
 145          $this->TimeArray = preg_replace( '/.+/', '%$0', $this->TimePHPArray );
 146          $this->DateArray = preg_replace( '/.+/', '%$0', $this->DatePHPArray );
 147          $this->DateTimeArray = preg_replace( '/.+/', '%$0', $this->DateTimePHPArray );
 148  
 149          $this->TimeSlashInputArray = preg_replace( '/.+/', '/(?<!%)$0/', $this->TimePHPArray );
 150          $this->DateSlashInputArray = preg_replace( '/.+/', '/(?<!%)$0/', $this->DatePHPArray );
 151          $this->DateTimeSlashInputArray = preg_replace( '/.+/', '/(?<!%)$0/', $this->DateTimePHPArray );
 152  
 153          $this->TimeSlashOutputArray = preg_replace( '/.+/', '\\\\$0', $this->TimePHPArray );
 154          $this->DateSlashOutputArray = preg_replace( '/.+/', '\\\\$0', $this->DatePHPArray );
 155          $this->DateTimeSlashOutputArray = preg_replace( '/.+/', '\\\\$0', $this->DateTimePHPArray );
 156  
 157          $this->HTTPLocaleCode = '';
 158          $this->functionMap = array(
 159              'time' => 'formatTime',
 160              'shorttime' => 'formatShortTime',
 161              'date' => 'formatDate',
 162              'shortdate' => 'formatShortDate',
 163              'datetime' => 'formatDateTime',
 164              'shortdatetime' => 'formatShortDateTime',
 165              'currency' => 'formatCurrencyWithSymbol',
 166              'clean_currency' => 'formatCleanCurrency',
 167              'number' => 'formatNumber',
 168          );
 169  
 170          $this->DayNames = array( 0 => 'sun', 1 => 'mon', 2 => 'tue',
 171                                   3 => 'wed', 4 => 'thu', 5 => 'fri', 6 => 'sat' );
 172          $this->MonthNames = array( 1 => 'jan', 2 => 'feb', 3 => 'mar',
 173                                     4 => 'apr', 5 => 'may', 6 => 'jun',
 174                                     7 => 'jul', 8 => 'aug', 9 => 'sep',
 175                                     10 => 'oct', 11 => 'nov', 12 => 'dec' );
 176          $this->WeekDays = array( 0, 1, 2, 3, 4, 5, 6 );
 177          $this->Months = array( 1, 2, 3, 4, 5, 6,
 178                                 7, 8, 9, 10, 11, 12 );
 179  
 180          $locale = eZLocale::localeInformation( $localeString );
 181  
 182          $this->CountryCode = $locale['country'];
 183          $this->CountryVariation = $locale['country-variation'];
 184          $this->LanguageCode = $locale['language'];
 185          $this->LocaleCode = $locale['locale'];
 186          $this->TranslationCode = $locale['locale'];
 187          $this->Charset = $locale['charset'];
 188          $this->OverrideCharset = $locale['charset'];
 189  
 190          $this->LocaleINI = array( 'default' => null, 'variation' => null );
 191          $this->CountryINI = array( 'default' => null, 'variation' => null );
 192          $this->LanguageINI = array( 'default' => null, 'variation' => null );
 193  
 194          // Figure out if we use one locale file or separate country/language file.
 195          $localeINI =& $this->localeFile();
 196          $countryINI =& $localeINI;
 197          $languageINI =& $localeINI;
 198          if ( $localeINI === null )
 199          {
 200              $countryINI =& $this->countryFile();
 201              $languageINI =& $this->languageFile();
 202          }
 203  
 204          $this->reset();
 205  
 206          $this->IsValid = true;
 207  
 208          // Load country information
 209          if ( $countryINI !== null )
 210          {
 211              $this->initCountry( $countryINI );
 212          }
 213          else
 214          {
 215              $this->IsValid = false;
 216              eZDebug::writeError( 'Could not load country settings for ' . $this->CountryCode, 'eZLocale' );
 217          }
 218  
 219          // Load language information
 220          if ( $languageINI !== null )
 221          {
 222              $this->initLanguage( $languageINI );
 223          }
 224          else
 225          {
 226              $this->IsValid = false;
 227              eZDebug::writeError( 'Could not load language settings for ' . $this->LanguageCode, 'eZLocale' );
 228          }
 229  
 230  
 231          // Load variation if any
 232          if ( $this->countryVariation() )
 233          {
 234              $localeVariationINI =& $this->localeFile( true );
 235              $countryVariationINI = $localeVariationINI;
 236              $languageVariationINI = $localeVariationINI;
 237              if ( $localeVariationINI === null )
 238              {
 239                  $countryVariationINI = $this->countryFile( true );
 240                  $languageVariationINI = $this->languageFile( true );
 241              }
 242  
 243              // Load country information
 244              if ( $countryVariationINI !== null )
 245              {
 246                  $this->initCountry( $countryVariationINI );
 247              }
 248  
 249              // Load language information
 250              if ( $languageVariationINI !== null )
 251              {
 252                  $this->initLanguage( $languageVariationINI );
 253              }
 254          }
 255  
 256          if ( $this->MondayFirst )
 257          {
 258              $this->WeekDays[] = array_shift( $this->WeekDays );
 259          }
 260  
 261          $this->AM = 'am';
 262          $this->PM = 'pm';
 263      }
 264  
 265      /*!
 266       \private
 267      */
 268      function reset()
 269      {
 270          $this->TimeFormat = '';
 271          $this->ShortTimeFormat = '';
 272          $this->DateFormat = '';
 273          $this->ShortDateFormat = '';
 274          $this->DateTimeFormat = '';
 275          $this->ShortDateTimeFormat = '';
 276  
 277          $this->MondayFirst = false;
 278  
 279          $this->Country = '';
 280          $this->CountryComment = '';
 281  
 282          $this->DecimalSymbol = '';
 283          $this->ThousandsSeparator = '';
 284          $this->FractDigits = 2;
 285          $this->NegativeSymbol = '-';
 286          $this->PositiveSymbol = '';
 287  
 288          $this->CurrencyDecimalSymbol = '';
 289          $this->CurrencyName = '';
 290          $this->CurrencyShortName = '';
 291          $this->CurrencyThousandsSeparator = '';
 292          $this->CurrencyFractDigits = 2;
 293          $this->CurrencyNegativeSymbol = '-';
 294          $this->CurrencyPositiveSymbol = '';
 295          $this->CurrencySymbol = '';
 296          $this->CurrencyPositiveFormat = '';
 297          $this->CurrencyNegativeFormat = '';
 298          $this->CountryNames = '';
 299  
 300          $this->LanguageName = '';
 301          $this->LanguageComment = '';
 302          $this->IntlLanguageName = '';
 303          $this->AllowedCharsets = array();
 304  
 305          $this->ShortDayNames = array();
 306          $this->LongDayNames = array();
 307          foreach ( $this->DayNames as $day )
 308          {
 309              $this->ShortDayNames[$day] = '';
 310              $this->LongDayNames[$day] = '';
 311          }
 312  
 313          $this->ShortMonthNames = array();
 314          $this->LongMonthNames = array();
 315          foreach ( $this->MonthNames as $month )
 316          {
 317              $this->ShortMonthNames[$month] = '';
 318              $this->LongMonthNames[$month] = '';
 319          }
 320  
 321          $this->ShortWeekDayNames = array();
 322          $this->LongWeekDayNames = array();
 323          foreach( $this->WeekDays as $wday )
 324          {
 325              $code = $this->DayNames[$wday];
 326              $this->ShortWeekDayNames[$wday] = '';
 327              $this->LongWeekDayNames[$wday] = '';
 328          }
 329      }
 330  
 331      /*!
 332       \return true if the locale is valid, ie the locale file could be loaded.
 333      */
 334      function isValid()
 335      {
 336          return $this->IsValid;
 337      }
 338  
 339      /*!
 340       \private
 341      */
 342      function initCountry( &$countryINI )
 343      {
 344          $countryINI->assign( 'DateTime', 'TimeFormat', $this->TimeFormat );
 345          $countryINI->assign( 'DateTime', 'ShortTimeFormat', $this->ShortTimeFormat );
 346          $countryINI->assign( 'DateTime', 'DateFormat', $this->DateFormat );
 347          $countryINI->assign( 'DateTime', 'ShortDateFormat', $this->ShortDateFormat );
 348          $countryINI->assign( 'DateTime', 'DateTimeFormat', $this->DateTimeFormat );
 349          $countryINI->assign( 'DateTime', 'ShortDateTimeFormat', $this->ShortDateTimeFormat );
 350  
 351          if ( $countryINI->hasVariable( 'DateTime', 'MondayFirst' ) )
 352              $this->MondayFirst = strtolower( $countryINI->variable( 'DateTime', 'MondayFirst' ) ) == 'yes';
 353  
 354          $countryINI->assign( 'RegionalSettings', 'Country', $this->Country );
 355          $countryINI->assign( "RegionalSettings", "CountryComment", $this->CountryComment );
 356  
 357          $countryINI->assign( 'Numbers', 'DecimalSymbol', $this->DecimalSymbol );
 358          $countryINI->assign( 'Numbers', 'ThousandsSeparator', $this->ThousandsSeparator );
 359          $countryINI->assign( 'Numbers', 'FractDigits', $this->FractDigits );
 360          $countryINI->assign( 'Numbers', 'NegativeSymbol', $this->NegativeSymbol );
 361          $countryINI->assign( 'Numbers', 'PositiveSymbol', $this->PositiveSymbol );
 362  
 363          $countryINI->assign( 'Currency', 'DecimalSymbol', $this->CurrencyDecimalSymbol );
 364          $countryINI->assign( 'Currency', 'Name', $this->CurrencyName );
 365          $countryINI->assign( 'Currency', 'ShortName', $this->CurrencyShortName );
 366          $countryINI->assign( 'Currency', 'ThousandsSeparator', $this->CurrencyThousandsSeparator );
 367          $countryINI->assign( 'Currency', 'FractDigits', $this->CurrencyFractDigits );
 368          $countryINI->assign( 'Currency', 'NegativeSymbol', $this->CurrencyNegativeSymbol );
 369          $countryINI->assign( 'Currency', 'PositiveSymbol', $this->CurrencyPositiveSymbol );
 370          $countryINI->assign( 'Currency', 'Symbol', $this->CurrencySymbol );
 371          $countryINI->assign( 'Currency', 'PositiveFormat', $this->CurrencyPositiveFormat );
 372          $countryINI->assign( 'Currency', 'NegativeFormat', $this->CurrencyNegativeFormat );
 373          if ( $countryINI->hasVariable( 'CountryNames', 'Countries' ) )
 374              $this->CountryNames = $countryINI->variable( 'CountryNames', 'Countries' );
 375  
 376      }
 377  
 378      /*!
 379       \private
 380      */
 381      function initLanguage( &$languageINI )
 382      {
 383          $languageINI->assign( "RegionalSettings", "LanguageName", $this->LanguageName );
 384          $languageINI->assign( "RegionalSettings", "InternationalLanguageName", $this->IntlLanguageName );
 385          $languageINI->assign( "RegionalSettings", "LanguageComment", $this->LanguageComment );
 386          $languageINI->assign( 'RegionalSettings', 'TranslationCode', $this->TranslationCode );
 387  
 388          if ( $this->OverrideCharset == '' )
 389          {
 390              $charset = false;
 391              if ( $languageINI->hasVariable( 'Charset', 'Preferred' ) )
 392              {
 393                  $charset = $languageINI->variable( 'Charset', 'Preferred' );
 394                  if ( $charset != '' )
 395                      $this->Charset = $charset;
 396              }
 397          }
 398          if ( $languageINI->hasVariable( 'Charset', 'Allowed' ) )
 399          {
 400              $this->AllowedCharsets = $languageINI->variable( 'Charset', 'Allowed' );
 401          }
 402          else
 403          {
 404              if ( $languageINI->hasVariable( 'Charset', 'Preferred' ) )
 405                  $this->AllowedCharsets[] = $languageINI->variable( 'Charset', 'Preferred' );
 406          }
 407  
 408  
 409          if ( !is_array( $this->ShortDayNames ) )
 410              $this->ShortDayNames = array();
 411          if ( !is_array( $this->LongDayNames ) )
 412              $this->LongDayNames = array();
 413  
 414          $tmpShortDayNames = array();
 415          if ( $languageINI->hasGroup( 'ShortDayNames' ) )
 416              $tmpShortDayNames = $languageINI->variableMulti( 'ShortDayNames', $this->DayNames );
 417          $tmpLongDayNames = array();
 418          if ( $languageINI->hasGroup( 'LongDayNames' ) )
 419              $tmpLongDayNames = $languageINI->variableMulti( 'LongDayNames', $this->DayNames );
 420          foreach ( $this->DayNames as $key => $day )
 421          {
 422              if ( isset( $tmpShortDayNames[$key] ) )
 423                  $this->ShortDayNames[$day] = $tmpShortDayNames[$key];
 424              if ( isset( $tmpLongDayNames[$key] ) )
 425                  $this->LongDayNames[$day] = $tmpLongDayNames[$key];
 426          }
 427  
 428  
 429          if ( !is_array( $this->ShortMonthNames ) )
 430              $this->LongMonthNames = array();
 431          if ( !is_array( $this->ShortMonthNames ) )
 432              $this->LongMonthNames = array();
 433  
 434          $tmpShortMonthNames = array();
 435          if ( $languageINI->hasGroup( 'ShortMonthNames' ) )
 436              $tmpShortMonthNames = $languageINI->variableMulti( 'ShortMonthNames', $this->MonthNames );
 437          $tmpLongMonthNames = array();
 438          if ( $languageINI->hasGroup( 'LongMonthNames' ) )
 439              $tmpLongMonthNames = $languageINI->variableMulti( 'LongMonthNames', $this->MonthNames );
 440          foreach ( $this->MonthNames as $key => $day )
 441          {
 442              if ( isset( $tmpShortMonthNames[$key] ) )
 443                  $this->ShortMonthNames[$day] = $tmpShortMonthNames[$key];
 444              if ( isset( $tmpLongMonthNames[$key] ) )
 445                  $this->LongMonthNames[$day] = $tmpLongMonthNames[$key];
 446          }
 447  
 448  
 449          if ( !is_array( $this->ShortWeekDayNames ) )
 450              $this->ShortWeekDayNames = array();
 451          if ( !is_array( $this->LongWeekDayNames ) )
 452              $this->LongWeekDayNames = array();
 453  
 454          foreach ( $this->WeekDays as $key => $day )
 455          {
 456              if ( isset( $tmpShortDayNames[$key] ) )
 457                  $this->ShortWeekDayNames[$day] = $tmpShortDayNames[$key];
 458              if ( isset( $tmpLongDayNames[$key] ) )
 459                  $this->LongWeekDayNames[$day] = $tmpLongDayNames[$key];
 460          }
 461  
 462          if ( $languageINI->hasVariable( 'HTTP', 'ContentLanguage' ) )
 463              $this->HTTPLocaleCode = $languageINI->variable( 'HTTP', 'ContentLanguage' );
 464      }
 465  
 466      /*!
 467       \return a regexp which can be used for locale matching.
 468       The following groups are defiend
 469       - 1 - The language identifier
 470       - 2 - The separator and the country (3)
 471       - 3 - The country identifier
 472       - 4 - The separator and the charset (5)
 473       - 5 - The charset
 474       - 6 - The separator and the variation (7)
 475       - 7 - The variation
 476       \note The groyps 4 and 5 will only be used if \a $withCharset is \c true.
 477             The groups 6 and 7 will only be used if \a $withVariations is \c true.
 478       \param $withVariations If \c true it will include variations of locales (ends with @identifier)
 479      */
 480      function localeRegexp( $withVariations = true, $withCharset = true )
 481      {
 482          return "([a-zA-Z]+)([_-]([a-zA-Z]+))?" . ( $withCharset ? "(\.([a-zA-Z-]+))?" : '' ) . ( $withVariations ? "(@([a-zA-Z0-9]+))?" : '' );
 483      }
 484  
 485      /*!
 486       Decodes a locale string into language, country and charset and returns an array with the information.
 487       Country and charset is optional, country is specified with a - or _ followed by the country code (NO, GB),
 488       charset is specified with a . followed by the charset name.
 489       Examples of locale strings are: nor-NO, en_GB.utf8, nn_NO
 490      */
 491      function localeInformation( $localeString )
 492      {
 493          $info = null;
 494          if ( preg_match( '/^([a-zA-Z]+)([_-]([a-zA-Z]+))?(\.([a-zA-Z-]+))?(@([a-zA-Z0-9]+))?/', $localeString, $regs ) )
 495          {
 496              $info = array();
 497              $language = strtolower( $regs[1] );
 498              $country = '';
 499              if ( isset( $regs[3] ) )
 500                  $country = strtoupper( $regs[3] );
 501              $charset = '';
 502              if ( isset( $regs[5] ) )
 503                  $charset = strtolower( $regs[5] );
 504              $countryVariation = '';
 505              if ( isset( $regs[7] ) )
 506                  $countryVariation = strtolower( $regs[7] );
 507              $locale = $language;
 508              if ( $country !== '' )
 509                  $locale .= '-' . $country;
 510              $info['language'] = $language;
 511              $info['country'] = $country;
 512              $info['country-variation'] = $countryVariation;
 513              $info['charset'] = $charset;
 514              $info['locale'] = $locale;
 515          }
 516          else
 517          {
 518              $info = array();
 519              $locale = strtolower( $localeString );
 520              $language = $locale;
 521              $info['language'] = $language;
 522              $info['country'] = '';
 523              $info['country-variation'] = '';
 524              $info['charset'] = '';
 525              $info['locale'] = $locale;
 526          }
 527          return $info;
 528      }
 529  
 530      /*!
 531       Sets locale information in PHP. This means that some of the string/sort functions in
 532       PHP will work with non-latin1 characters.
 533       Make sure setLanguage is called before this.
 534      */
 535      function initPHP( $charset = false )
 536      {
 537          if ( $charset === false )
 538              $charset = $this->Language->code();
 539          setlocale( LC_ALL, $charset );
 540      }
 541  
 542      function attributes()
 543      {
 544          return array_keys( eZLocale::attributeFunctionMap() );
 545      }
 546  
 547      function hasAttribute( $attribute )
 548      {
 549          $attributeMap = eZLocale::attributeFunctionMap();
 550          if ( isset( $attributeMap[$attribute] ) )
 551              return true;
 552          else
 553              return false;
 554      }
 555  
 556      function &attribute( $attribute )
 557      {
 558          $attributeMap = eZLocale::attributeFunctionMap();
 559          if ( isset( $attributeMap[$attribute] ) )
 560          {
 561              $method = $attributeMap[$attribute];
 562              if ( method_exists( $this, $method ) )
 563              {
 564                  $retValue = $this->$method();
 565              }
 566              else
 567              {
 568                  eZDebug::writeError( "Unknown method '$method' specified for attribute '$attribute'", 'eZLocale::attribute' );
 569                  $retValue = null;
 570              }
 571          }
 572          else
 573          {
 574              eZDebug::writeError( "Attribute '$attribute' does not exist", 'eZLocale::attribute' );
 575              $retValue = null;
 576          }
 577          return $retValue;
 578      }
 579  
 580      function attributeFunctionMap()
 581      {
 582          return array( 'charset' => 'charset',
 583                        'allowed_charsets' => 'allowedCharsets',
 584                        'country_name' => 'countryName',
 585                        'country_comment' => 'countryComment',
 586                        'country_code' => 'countryCode',
 587                        'country_variation' => 'countryVariation',
 588                        'language_name' => 'languageName',
 589                        'intl_language_name' => 'internationalLanguageName',
 590                        'language_code' => 'languageCode',
 591                        'language_comment' => 'languageComment',
 592                        'locale_code' => 'localeCode',
 593                        'locale_full_code' => 'localeFullCode',
 594                        'http_locale_code' => 'httpLocaleCode',
 595                        'decimal_symbol' => 'decimalSymbol',
 596                        'thousands_separator' => 'thousandsSeparator',
 597                        'decimal_count' => 'decimalCount',
 598                        'negative_symbol' => 'negativeSymbol',
 599                        'positive_symbol' => 'positiveSymbol',
 600                        'currency_decimal_symbol' => 'currencyDecimalSymbol',
 601                        'currency_thousands_separator' => 'currencyThousandsSeparator',
 602                        'currency_decimal_count' => 'currencyDecimalCount',
 603                        'currency_negative_symbol' => 'currencyNegativeSymbol',
 604                        'currency_positive_symbol' => 'currencyPositiveSymbol',
 605                        'currency_symbol' => 'currencySymbol',
 606                        'currency_name' => 'currencyName',
 607                        'currency_short_name' => 'currencyShortName',
 608                        'is_monday_first' => 'isMondayFirst',
 609                        'weekday_name_list' => 'weekDayNames',
 610                        'weekday_short_name_list' => 'weekDayShortNames',
 611                        'weekday_number_list' => 'weekDays',
 612                        'month_list' => 'months',
 613                        'month_name_list' => 'monthsNames',
 614                        'is_valid' => 'isValid' );
 615      }
 616  
 617      /*!
 618       Returns the charset for this locale.
 619       \note It returns an empty string if no charset was set from the locale file.
 620      */
 621      function charset()
 622      {
 623          return $this->Charset;
 624      }
 625  
 626      /*!
 627       \return an array with charsets that this locale can work with.
 628      */
 629      function allowedCharsets()
 630      {
 631          return $this->AllowedCharsets;
 632      }
 633  
 634      /*!
 635       Returns the name of the country in British English.
 636      */
 637      function countryName()
 638      {
 639          return $this->Country;
 640      }
 641  
 642      /*!
 643       Returns the comment for the country, if any.
 644      */
 645      function countryComment()
 646      {
 647          return $this->CountryComment;
 648      }
 649  
 650      /*!
 651       Returns the code for the country. eg. 'NO'
 652      */
 653      function countryCode()
 654      {
 655          return $this->CountryCode;
 656      }
 657  
 658      /*!
 659       Returns the variation for the country. eg. 'spraakraad'
 660      */
 661      function countryVariation()
 662      {
 663          return $this->CountryVariation;
 664      }
 665  
 666      /*!
 667       Returns the language code for this language, for instance nor for norwegian or eng for english.
 668      */
 669      function languageCode()
 670      {
 671          return $this->LanguageCode;
 672      }
 673  
 674      /*!
 675       Returns the comment for the language, if any.
 676      */
 677      function languageComment()
 678      {
 679          return $this->LanguageComment;
 680      }
 681  
 682      /*!
 683       Returns the locale code which is used for translation files. Normally this is the same as localeCode()
 684       but for some locales translation from other languages can be used
 685  
 686       e.g. por-MZ (Mozambique) uses por-PT for translation.
 687      */
 688      function translationCode()
 689      {
 690          return $this->TranslationCode;
 691      }
 692  
 693      /*!
 694       Returns the locale code for this language which is the language and the country with a dash (-) between them,
 695       for instance nor-NO or eng-GB.
 696      */
 697      function localeCode()
 698      {
 699          return $this->LocaleCode;
 700      }
 701  
 702      /*!
 703       Same as localeCode() but appends the country variation if it is set.
 704      */
 705      function localeFullCode()
 706      {
 707          $locale = $this->LocaleCode;
 708          $variation = $this->countryVariation();
 709          if ( $variation )
 710              $locale .= "@" . $variation;
 711          return $locale;
 712      }
 713  
 714      /*!
 715       \return the locale code which can be set in either HTTP headers or the HTML file.
 716               The locale code is first check for in the RegionalSettings/HTTPLocale setting in site.ini,
 717               if that is empty it will use the value from localeCode().
 718       \sa localeCode
 719      */
 720      function httpLocaleCode()
 721      {
 722          $ini =& eZINI::instance();
 723          $localeCode = '';
 724          if ( $ini->hasVariable( 'RegionalSettings', 'HTTPLocale' ) )
 725          {
 726              $localeCode = $ini->variable( 'RegionalSettings', 'HTTPLocale' );
 727          }
 728          if ( $localeCode == '' and
 729               $this->HTTPLocaleCode != '' )
 730              $localeCode = $this->HTTPLocaleCode;
 731          if ( $localeCode == '' )
 732              $localeCode = $this->localeCode();
 733          return $localeCode;
 734      }
 735  
 736      /*!
 737       \static
 738       Returns the current locale code for this language which is the language and the country with a dash (-) between them,
 739       for instance nor-NO or eng-GB.
 740       \sa localeCode, instance
 741      */
 742      function currentLocaleCode()
 743      {
 744          $locale =& eZLocale::instance();
 745          return $locale->localeCode();
 746      }
 747  
 748      /*!
 749       Returns the name of the language in its own tounge.
 750      */
 751      function languageName()
 752      {
 753          return $this->LanguageName;
 754      }
 755  
 756      /*!
 757       Returns the name of the language in English (eng).
 758      */
 759      function internationalLanguageName()
 760      {
 761          return $this->IntlLanguageName;
 762      }
 763  
 764      /*!
 765       Returns the currency symbol for this locale.
 766      */
 767      function currencySymbol()
 768      {
 769          return $this->CurrencySymbol;
 770      }
 771  
 772      /*!
 773       Returns the name of the currency.
 774      */
 775      function currencyName()
 776      {
 777          return $this->CurrencyName;
 778      }
 779  
 780      /*!
 781       Returns the short name of the currency.
 782      */
 783      function currencyShortName()
 784      {
 785          return $this->CurrencyShortName;
 786      }
 787  
 788      /*!
 789       Returns true if the week starts with monday, false if sunday.
 790       \sa weekDays()
 791      */
 792      function isMondayFirst()
 793      {
 794          return $this->MondayFirst;
 795      }
 796  
 797      /*!
 798       \return the decimal symbol for normal numbers.
 799      */
 800      function decimalSymbol()
 801      {
 802          return $this->DecimalSymbol;
 803      }
 804  
 805      /*!
 806       \return the thousand separator for normal numbers.
 807      */
 808      function thousandsSeparator()
 809      {
 810          return $this->ThousandsSeparator;
 811      }
 812  
 813      /*!
 814       \return the number of decimals for normal numbers.
 815      */
 816      function decimalCount()
 817      {
 818          return $this->FractDigits;
 819      }
 820  
 821      /*!
 822       \return the negative symbol for normal numbers.
 823      */
 824      function negativeSymbol()
 825      {
 826          return $this->NegativeSymbol;
 827      }
 828  
 829      /*!
 830       \return the positive symbol for normal numbers.
 831      */
 832      function positiveSymbol()
 833      {
 834          return $this->PositiveSymbol;
 835      }
 836  
 837      /*!
 838       \return the decimal symbol for currencies.
 839      */
 840      function currencyDecimalSymbol()
 841      {
 842          return $this->CurrencyDecimalSymbol;
 843      }
 844  
 845      /*!
 846       \return the thousand separator for currencies.
 847      */
 848      function currencyThousandsSeparator()
 849      {
 850          return $this->CurrencyThousandsSeparator;
 851      }
 852  
 853      /*!
 854       \return the number of decimals for currencies.
 855      */
 856      function currencyDecimalCount()
 857      {
 858          return $this->CurrencyFractDigits;
 859      }
 860  
 861      /*!
 862       \return the negative symbol for currencies.
 863      */
 864      function currencyNegativeSymbol()
 865      {
 866          return $this->CurrencyNegativeSymbol;
 867      }
 868  
 869      /*!
 870       \return the positive symbol for currencies.
 871      */
 872      function currencyPositiveSymbol()
 873      {
 874          return $this->CurrencyPositiveSymbol;
 875      }
 876  
 877      /*!
 878       Returns an array with the days of the week according to locale information.
 879       Each entry in the array can be supplied to the shortDayName() and longDayName() functions.
 880       \sa isMondayFirst(), weekDayNames()
 881      */
 882      function weekDays()
 883      {
 884          return $this->WeekDays;
 885      }
 886  
 887      /*!
 888       Returns the months of the year as an array. This only supplied for completeness.
 889       \sa weekDays(), monthsNames()
 890      */
 891      function months()
 892      {
 893          return $this->Months;
 894      }
 895  
 896      /*!
 897       Returns the names of months as an array.
 898       \sa months()
 899      */
 900      function monthsNames()
 901      {
 902          return $this->LongMonthNames;
 903      }
 904  
 905      /*!
 906       Returns the same array as in weekDays() but with all days translated to text.
 907      */
 908      function weekDayNames( $short = false )
 909      {
 910          if ( $short )
 911              $dayList = $this->ShortWeekDayNames;
 912          else
 913              $dayList = $this->LongWeekDayNames;
 914  
 915          $resultDayList = array();
 916          foreach ( $this->WeekDays as $day )
 917          {
 918              $resultDayList[ $day ] = $dayList[ $day ];
 919          }
 920          return $resultDayList;
 921      }
 922  
 923      /*!
 924       Returns the same array as in weekDayNames() but with short version of days.
 925      */
 926      function weekDayShortNames()
 927      {
 928          return $this->weekDayNames( true );
 929      }
 930  
 931      /*!
 932       Returns the method name belonging to a qualifier
 933      */
 934      function getFormattingFunction( $qualifier )
 935      {
 936          if ( isset( $this->functionMap[$qualifier] ) )
 937          {
 938              return $this->functionMap[$qualifier];
 939          }
 940          else
 941          {
 942              return false;
 943          }
 944      }
 945  
 946      /*!
 947       Formats the time $time according to locale information and returns it. If $time
 948       is not specified the current time is used.
 949      */
 950      function formatTime( $time = false )
 951      {
 952          return $this->formatTimeType( $this->TimeFormat, $time );
 953      }
 954  
 955      /*!
 956       Formats the time $time according to locale information for short times and returns it. If $time
 957       is not specified the current time is used.
 958      */
 959      function formatShortTime( $time = false )
 960      {
 961          return $this->formatTimeType( $this->ShortTimeFormat, $time );
 962      }
 963  
 964      /*!
 965       Formats the time $time according to the format $fmt. You shouldn't call this
 966       directly unless you want to deviate from the locale settings.
 967       \sa formatTime(), formatShortTime()
 968      */
 969      function formatTimeType( $fmt, $time = false )
 970      {
 971          if ( $time == false )
 972              $time = time();
 973  
 974          $text = date( eZLocale::transformToPHPFormat( $fmt, $this->TimePHPArray ), $time );
 975          return  str_replace( array( '%a', '%A' ),
 976                               array( $this->meridiemName( $time, false ),
 977                                      $this->meridiemName( $time, true ) ),
 978                               $text );
 979      }
 980  
 981      /*!
 982       Returns the name for the meridiem ie am (ante meridiem) or pm (post meridiem).
 983       If $time is not supplied or false the current time is used. If $upcase is false
 984       the name is in lowercase otherwise uppercase.
 985       The time is defined to be am if the hour is less than 12 and pm otherwise. Normally
 986       the hours 00 and 12 does not have am/pm attached and are instead called Midnight and Noon,
 987       but for simplicity the am/pm is always attached (if the locale allows it).
 988      */
 989      function meridiemName( $time = false, $upcase = false )
 990      {
 991          if ( $time == false )
 992              $time = mktime();
 993          $hour = date( 'G', $time );
 994          $name = $hour < 12 ? $this->AM : $this->PM;
 995          if ( $upcase )
 996              $name = strtoupper( $name );
 997          return $name;
 998      }
 999  
1000      /*!
1001       Formats the date $date according to locale information and returns it. If $date
1002       is not specified the current date is used.
1003      */
1004      function formatDate( $date = false )
1005      {
1006          return $this->formatDateType( $this->DateFormat, $date );
1007      }
1008  
1009      /*!
1010       Formats the date $date according to locale information for short dates and returns it. If $date
1011       is not specified the current date is used.
1012      */
1013      function formatShortDate( $date = false )
1014      {
1015          return $this->formatDateType( $this->ShortDateFormat, $date );
1016      }
1017  
1018      /*!
1019       Formats the date and time $date according to locale information and returns it. If $date
1020       is not specified the current date is used.
1021      */
1022      function formatDateTime( $date = false )
1023      {
1024          return $this->formatDateTimeType( $this->DateTimeFormat, $date );
1025      }
1026  
1027      /*!
1028       Formats the date and time $date according to locale information for short dates and returns it.
1029       If $date is not specified the current date is used.
1030      */
1031      function formatShortDateTime( $date = false )
1032      {
1033          return $this->formatDateTimeType( $this->ShortDateTimeFormat, $date );
1034      }
1035  
1036      /*!
1037       Formats the date $date according to the format $fmt. You shouldn't call this
1038       directly unless you want to deviate from the locale settings.
1039       \sa formatDate(), formatShortDate()
1040      */
1041      function formatDateType( $fmt, $date = false )
1042      {
1043          if ( $date === false )
1044              $date = time();
1045  
1046          $text = date( eZLocale::transformToPHPFormat( $fmt, $this->DatePHPArray ), $date );
1047          return str_replace( array( '%D', '%l', '%M', '%F' ),
1048                              array( $this->shortDayName( date( 'w', $date ) ),
1049                                     $this->longDayName( date( 'w', $date ) ),
1050                                     $this->shortMonthName( date( 'n', $date ) ),
1051                                     $this->longMonthName( date( 'n', $date ) ) ),
1052                              $text );
1053      }
1054  
1055      /*!
1056       Formats the date and time \a $datetime according to the format \a $fmt.
1057       You shouldn't call this directly unless you want to deviate from the locale settings.
1058       \sa formatDateTime(), formatShortDateTime()
1059      */
1060      function formatDateTimeType( $fmt, $datetime = false )
1061      {
1062          if ( $datetime === false )
1063              $datetime = time();
1064  
1065          $text = date( eZLocale::transformToPHPFormat( $fmt, $this->DateTimePHPArray ), $datetime );
1066          // Replace some special 'date' formats that needs to be handled
1067          // internally by the i18n system and not by PHP
1068          return str_replace( array( '%D', '%l', '%M', '%F',
1069                                     '%a', '%A' ),
1070                              array( $this->shortDayName( date( 'w', $datetime ) ),
1071                                     $this->longDayName( date( 'w', $datetime ) ),
1072                                     $this->shortMonthName( date( 'n', $datetime ) ),
1073                                     $this->longMonthName( date( 'n', $datetime ) ),
1074                                     $this->meridiemName( $datetime, false ),
1075                                     $this->meridiemName( $datetime, true ) ),
1076                              $text );
1077      }
1078  
1079      /*!
1080       \private
1081       \static
1082       Transforms the date/time string \a $fmt into a string that can be
1083       passed to the PHP function 'date'.
1084       \param $fmt An eZ publish locale format, %x means a 'formatting character' from PHPs 'date' function.
1085       \param $allowed An array with characters that are considered allowed 'formatting characters'
1086                       Any character not found in this array will be kept intact by escaping it.
1087       \sa http://www.php.net/manual/en/function.date.php
1088      */
1089      function transformToPHPFormat( $fmt, $allowed )
1090      {
1091          // This goes trough each of the characters in the format
1092          // string $fmt, if a valid %x character is found it is replaced
1093          // with just x (like date expects).
1094          // It will also escape all characters in the range a-z and A-Z
1095          // expect does that are valid %x formats.
1096          // A special case is formats of the type %%, they will become %
1097          $dateFmt = '';
1098          $offs = 0;
1099          $len = strlen( $fmt );
1100          while ( $offs < $len )
1101          {
1102              $char = $fmt[$offs];
1103              if ( $char == '%' )
1104              {
1105                  if ( $offs + 1 < $len )
1106                  {
1107                      $type = $fmt[$offs + 1];
1108                      if ( $type == '%' )
1109                      {
1110                          $dateFmt .= '%';
1111                      }
1112                      else if ( ( $type >= 'a' and $type <= 'z' ) or
1113                                ( $type >= 'A' and $type <= 'Z' ) )
1114                      {
1115                          // Escape the $type character if it is not in
1116                          // the allowed 'format character' list
1117                          if ( !in_array( $type, $allowed ) )
1118                              $dateFmt .= '%\\';
1119                          $dateFmt .= $type;
1120                      }
1121                      else
1122                      {
1123                          $dateFmt .= $char . $type;
1124                      }
1125                      $offs += 2;
1126                  }
1127                  else
1128                  {
1129                      $dateFmt .= '\\' . $char;
1130                      ++$offs;
1131                  }
1132              }
1133              else
1134              {
1135                  // Escape a-zA-Z to avoid PHPs 'date' using them as a 'format character'
1136                  if ( ( $char >= 'a' and $char <= 'z' ) or
1137                       ( $char >= 'A' and $char <= 'Z' ) )
1138                      $dateFmt .= '\\';
1139                  $dateFmt .= $char;
1140                  ++$offs;
1141              }
1142          }
1143          return $dateFmt;
1144      }
1145  
1146      /*!
1147       Formats the number $number according to locale information and returns it.
1148      */
1149      function formatNumber( $number )
1150      {
1151          $neg = $number < 0;
1152          $num = $neg ? -$number : $number;
1153          $text = number_format( $num, $this->FractDigits, $this->DecimalSymbol, $this->ThousandsSeparator );
1154          return ( $neg ? $this->NegativeSymbol : $this->PositiveSymbol ) . $text;
1155      }
1156  
1157      /*!
1158       Formats the number according locale to the representation used internally in PHP
1159      */
1160      function internalNumber( $number )
1161      {
1162          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 ) ) )
1163          {
1164              $number = str_replace( ' ', '', $number );
1165              if ( $this->PositiveSymbol )
1166                  $number = str_replace( $this->PositiveSymbol, '', $number );
1167              $number = str_replace( $this->NegativeSymbol, '-', $number );
1168              $number = str_replace( $this->ThousandsSeparator, '', $number );
1169              $number = str_replace( $this->DecimalSymbol, '.', $number );
1170          }
1171          return $number;
1172      }
1173  
1174      /*!
1175       Formats the currency $number according to locale information and returns it. If $as_html
1176       is true all spaces are converted to &nbsp; before being returned ( depricated ).
1177      */
1178      function formatCurrency( $number, $as_html = true )
1179      {
1180          return $this->formatCurrencyWithSymbol( $number, $this->CurrencySymbol );
1181      }
1182  
1183      /*!
1184        Formats the same as formatCurrency, but drops the currency sign
1185  
1186        \param currency input
1187      */
1188      function formatCleanCurrency( $number )
1189      {
1190          $text = $this->formatCurrencyWithSymbol( $number, '', true );
1191          return trim( $text );
1192      }
1193  
1194      function formatCurrencyWithSymbol( $number, $symbol )
1195      {
1196          $neg = $number < 0;
1197          $num = $neg ? -$number : $number;
1198          $num_text = number_format( $num, $this->CurrencyFractDigits,
1199                                     $this->CurrencyDecimalSymbol, $this->CurrencyThousandsSeparator );
1200          return str_replace( array( '%c', '%p', '%q' ),
1201                              array( $symbol,
1202                                     $neg ? $this->CurrencyNegativeSymbol : $this->CurrencyPositiveSymbol,
1203                                     $num_text ),
1204                              $neg ? $this->CurrencyNegativeFormat : $this->CurrencyPositiveFormat );
1205      }
1206  
1207      function translatedCountryNames()
1208      {
1209          return $this->CountryNames;
1210      }
1211  
1212      /*!
1213       Formats the currency according locale to the representation used internally in PHP
1214      */
1215      function internalCurrency( $number )
1216      {
1217          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 ) ) )
1218          {
1219              $number = str_replace( ' ', '', $number );
1220              if ( $this->CurrencyPositiveSymbol )
1221                  $number = str_replace( $this->CurrencyPositiveSymbol, '', $number );
1222              $number = str_replace( $this->CurrencyNegativeSymbol, '-', $number );
1223              $number = str_replace( $this->CurrencyThousandsSeparator, '', $number );
1224              $number = str_replace( $this->CurrencyDecimalSymbol, '.', $number );
1225          }
1226          return $number;
1227      }
1228  
1229      /*!
1230       Returns the short name of the day number $num.
1231       The different numbers for the days are:
1232       Sunday    = 0
1233       Monday    = 1
1234       Tuesday   = 2
1235       Wednesday = 3
1236       Thursday  = 4
1237       Friday    = 5
1238       Saturday  = 6
1239       This functions is usually used together with weekDays().
1240       \sa longDayName()
1241      */
1242      function shortDayName( $num )
1243      {
1244          if ( $num >= 0 and $num <= 6 )
1245          {
1246              $code = $this->DayNames[$num];
1247              $name = $this->ShortDayNames[$code];
1248          }
1249          else
1250          {
1251              $name = null;
1252          }
1253          return $name;
1254      }
1255  
1256      /*!
1257       Returns the long name of the day number $num.
1258       The different numbers for the days are:
1259       Sunday    = 0
1260       Monday    = 1
1261       Tuesday   = 2
1262       Wednesday = 3
1263       Thursday  = 4
1264       Friday    = 5
1265       Saturday  = 6
1266       This functions is usually used together with weekDays().
1267       \sa shortDayName()
1268      */
1269      function longDayName( $num )
1270      {
1271          if ( $num >= 0 and $num <= 6 )
1272          {
1273              $code = $this->DayNames[$num];
1274              $name = $this->LongDayNames[$code];
1275          }
1276          else
1277          {
1278              $name = null;
1279          }
1280          return $name;
1281      }
1282  
1283      /*!
1284       Returns the short name of the month number $num.
1285       The different numbers for the months are:
1286       Januray   = 1
1287       February  = 2
1288       March     = 3
1289       April     = 4
1290       May       = 5
1291       June      = 6
1292       July      = 7
1293       August    = 8
1294       September = 9
1295       October   = 10
1296       November  = 11
1297       December  = 12
1298       This functions is usually used together with months().
1299       \sa longMonthName()
1300      */
1301      function shortMonthName( $num )
1302      {
1303          if ( $num >= 1 and $num <= 12 )
1304          {
1305              $code = $this->MonthNames[$num];
1306              $name = $this->ShortMonthNames[$code];
1307          }
1308          else
1309          {
1310              $name = null;
1311          }
1312          return $name;
1313      }
1314  
1315      /*!
1316       Returns the long name of the month number $num.
1317       The different numbers for the months are:
1318       Januray   = 1
1319       February  = 2
1320       March     = 3
1321       April     = 4
1322       May       = 5
1323       June      = 6
1324       July      = 7
1325       August    = 8
1326       September = 9
1327       October   = 10
1328       November  = 11
1329       December  = 12
1330       This functions is usually used together with months().
1331       \sa shortMonthName()
1332      */
1333      function longMonthName( $num )
1334      {
1335          if ( $num >= 1 and $num <= 12 )
1336          {
1337              $code = $this->MonthNames[$num];
1338              $name = $this->LongMonthNames[$code];
1339          }
1340          else
1341          {
1342              $name = null;
1343          }
1344          return $name;
1345      }
1346  
1347      /*!
1348       \static
1349       \return a list of locale objects which was found in the system.
1350       \param $asObject If \c true it returns each element as an eZLocale object
1351       \param $withVariations If \c true it will include variations of locales (ends with @identifier)
1352      */
1353      function localeList( $asObject = false, $withVariations = true )
1354      {
1355          $locales =& $GLOBALS['eZLocaleLocaleStringList'];
1356          if ( !is_array( $locales ) )
1357          {
1358              $localeRegexp = eZLocale::localeRegexp( $withVariations, false );
1359              $locales = array();
1360              $dir = opendir( 'share/locale' );
1361              while( ( $file = readdir( $dir ) ) !== false )
1362              {
1363                  if ( preg_match( "/^($localeRegexp)\.ini$/", $file, $regs ) )
1364                  {
1365                      $locales[] = $regs[1];
1366                  }
1367              }
1368              closedir( $dir );
1369              $locales = array_unique( $locales );
1370              sort( $locales );
1371              if ( $asObject )
1372              {
1373                  $localeObjects = array();
1374                  foreach ( $locales as $locale )
1375                  {
1376                      $localeInstance =& eZLocale::instance( $locale );
1377                      if ( $localeInstance )
1378                          $localeObjects[] = $localeInstance;
1379                  }
1380                  $locales = $localeObjects;
1381              }
1382          }
1383          return $locales;
1384      }
1385  
1386      /*!
1387       \static
1388       \return a list of countries which was found in the system, the countries are in identifier form,
1389               for instance: NO, GB, US
1390       \param $withVariations If \c true it will include variations of locales (ends with @identifier)
1391      */
1392      function countryList( $withVariations = true )
1393      {
1394          $countries =& $GLOBALS['eZLocaleCountryList'];
1395          if ( !is_array( $countries ) )
1396          {
1397              $localeRegexp = eZLocale::localeRegexp( $withVariations, false );
1398              $countries = array();
1399              $dir = opendir( 'share/locale' );
1400              while( ( $file = readdir( $dir ) ) !== false )
1401              {
1402                  if ( preg_match( "/^$localeRegexp\.ini$/", $file, $regs ) )
1403                  {
1404                      $countries[] = $regs[3];
1405                  }
1406              }
1407              closedir( $dir );
1408              sort( array_unique( $countries ) );
1409          }
1410          return $countries;
1411      }
1412  
1413      /*!
1414       \static
1415       \return a list of languages which was found in the system, the languages are in identifier form,
1416               for instance: nor, eng
1417       \param $withVariations If \c true it will include variations of locales (ends with @identifier)
1418      */
1419      function languageList( $withVariations = true )
1420      {
1421          $languages =& $GLOBALS['eZLocaleLanguageist'];
1422          if ( !is_array( $languages ) )
1423          {
1424              $localeRegexp = eZLocale::localeRegexp( $withVariations, false );
1425              $languages = array();
1426              $dir = opendir( 'share/locale' );
1427              while( ( $file = readdir( $dir ) ) !== false )
1428              {
1429                  if ( preg_match( "/^$localeRegexp\.ini$/", $file, $regs ) )
1430                  {
1431                      $languages[] = $regs[1];
1432                  }
1433              }
1434              closedir( $dir );
1435              sort( array_unique( $languages ) );
1436          }
1437          return $languages;
1438      }
1439  
1440  
1441      /*!
1442       Returns the eZINI object for the locale ini file.
1443       \warning Do not modify this object.
1444      */
1445      function &localeFile( $withVariation = false )
1446      {
1447          $type = $withVariation ? 'variation' : 'default';
1448          if ( get_class( $this->LocaleINI[$type] ) != 'ezini' )
1449          {
1450              $country = $this->countryCode();
1451              $countryVariation = $this->countryVariation();
1452              $language = $this->languageCode();
1453              $locale = $language;
1454              if ( $country !== '' )
1455                  $locale .= '-' . $country;
1456              if ( $withVariation )
1457              {
1458                  if ( $countryVariation !== '' )
1459                      $locale .= '@' . $countryVariation;
1460              }
1461              $localeFile = $locale . '.ini';
1462              if ( eZLocale::isDebugEnabled() )
1463                  eZDebug::writeNotice( "Requesting $localeFile", 'eZLocale::localeFile' );
1464              if ( eZINI::exists( $localeFile, 'share/locale' ) )
1465                  $this->LocaleINI[$type] = eZINI::instance( $localeFile, 'share/locale' );
1466          }
1467          return $this->LocaleINI[$type];
1468      }
1469  
1470      /*!
1471       Returns the eZINI object for the country ini file.
1472       \warning Do not modify this object.
1473      */
1474      function &countryFile( $withVariation = false )
1475      {
1476          $type = $withVariation ? 'variation' : 'default';
1477          if ( get_class( $this->CountryINI[$type] ) != 'ezini' )
1478          {
1479              $country = $this->countryCode();
1480              $countryVariation = $this->countryVariation();
1481              $locale = $country;
1482              if ( $withVariation )
1483              {
1484                  if ( $countryVariation !== '' )
1485                      $locale .= '@' . $countryVariation;
1486              }
1487              $countryFile = 'country/' . $locale . '.ini';
1488              if ( eZLocale::isDebugEnabled() )
1489                  eZDebug::writeNotice( "Requesting $countryFile", 'eZLocale::countryFile' );
1490              if ( eZINI::exists( $countryFile, 'share/locale' ) )
1491                  $this->CountryINI[$type] = eZINI::instance( $countryFile, 'share/locale' );
1492          }
1493          return $this->CountryINI[$type];
1494      }
1495  
1496      /*!
1497       Returns the eZINI object for the language ini file.
1498       \warning Do not modify this object.
1499      */
1500      function &languageFile( $withVariation = false )
1501      {
1502          $type = $withVariation ? 'variation' : 'default';
1503          if ( get_class( $this->LanguageINI[$type] ) != 'ezini' )
1504          {
1505              $language = $this->languageCode();
1506              $countryVariation = $this->countryVariation();
1507              $locale = $language;
1508              if ( $withVariation )
1509              {
1510                  if ( $countryVariation !== '' )
1511                      $locale .= '@' . $countryVariation;
1512              }
1513              $languageFile = 'language/' . $locale . '.ini';
1514              if ( eZLocale::isDebugEnabled() )
1515                  eZDebug::writeNotice( "Requesting $languageFile", 'eZLocale::languageFile' );
1516              if ( eZINI::exists( $languageFile, 'share/locale' ) )
1517                  $this->LanguageINI[$type] = eZINI::instance( $languageFile, 'share/locale' );
1518          }
1519          return $this->LanguageINI[$type];
1520      }
1521  
1522      /*!
1523       \static
1524       Returns an unique instance of the locale class for a given locale string. If $localeString is not
1525       specified the default local string in site.ini is used.
1526       Use this instead of newing eZLocale to benefit from speed and unified access.
1527       \note Use create() if you need to get a new unique copy you can alter.
1528      */
1529      function &instance( $localeString = false )
1530      {
1531          if ( $localeString === false )
1532          {
1533              $localeStringDefault =& $GLOBALS["eZLocaleStringDefault"];
1534              if (!isset( $localeStringDefault ) )
1535              {
1536                  $ini =& eZINI::instance();
1537                  $localeString = $ini->variable( 'RegionalSettings', 'Locale' );
1538                  /* Cache this answer to prevent countless calls to retrieve this
1539                   * from the INI settings */
1540                  $localeStringDefault = $localeString;
1541              }
1542              else
1543              {
1544                  /* Used cached version */
1545                  $localeString = $localeStringDefault;
1546              }
1547          }
1548          $instance =& $GLOBALS["eZLocaleInstance_$localeString"];
1549          if ( get_class( $instance ) != 'ezlocale' )
1550          {
1551              $instance = new eZLocale( $localeString );
1552          }
1553          return $instance;
1554      }
1555  
1556      /*!
1557       \static
1558       Similar to instance() but will always create a new copy.
1559      */
1560      function create( $localeString = false )
1561      {
1562          if ( $localeString === false )
1563          {
1564              $ini =& eZINI::instance();
1565              $localeString = $ini->variable( 'RegionalSettings', 'Locale' );
1566          }
1567          return new eZLocale( $localeString );
1568      }
1569  
1570      /*!
1571       \static
1572       \return true if debugging of internals is enabled, this will display
1573       which files are loaded and when cache files are created.
1574        Set the option with setIsDebugEnabled().
1575      */
1576      function isDebugEnabled()
1577      {
1578          if ( !isset( $GLOBALS['eZLocaleDebugInternalsEnabled'] ) )
1579               $GLOBALS['eZLocaleDebugInternalsEnabled'] = EZ_LOCALE_DEBUG_INTERNALS;
1580          return $GLOBALS['eZLocaleDebugInternalsEnabled'];
1581      }
1582  
1583      /*!
1584       \static
1585       Sets whether internal debugging is enabled or not.
1586      */
1587      function setIsDebugEnabled( $debug )
1588      {
1589          $GLOBALS['eZLocaleDebugInternalsEnabled'] = $debug;
1590      }
1591  
1592      //@{
1593      var $IsValid;
1594      //@}
1595  
1596      //@{
1597      /// Format of dates
1598      var $DateFormat;
1599      /// Format of short dates
1600      var $ShortDateFormat;
1601      /// Format of times
1602      var $TimeFormat;
1603      /// Format of short times
1604      var $ShortTimeFormat;
1605      /// True if monday is the first day of the week
1606      var $MondayFirst;
1607      /// AM and PM names
1608      var $AM, $PM;
1609      //@}
1610  
1611      //@{
1612      /// Numbers
1613      var $DecimalSymbol;
1614      var $ThousandsSeparator;
1615      var $FractDigits;
1616      var $NegativeSymbol;
1617      var $PositiveSymbol;
1618      //@}
1619  
1620      //@{
1621      /// Currency
1622      var $CurrencyDecimalSymbol;
1623      var $CurrencyThousandsSeparator;
1624      var $CurrencyFractDigits;
1625      var $CurrencyNegativeSymbol;
1626      var $CurrencyPositiveSymbol;
1627      var $CurrencySymbol;
1628      var $CurrencyPositiveFormat;
1629      var $CurrencyNegativeFormat;
1630      //@}
1631  
1632      //@{
1633      /// Help arrays
1634      var $DayNames;
1635      var $ShortDayNames, $LongDayNames;
1636      var $MonthNames;
1637      var $ShortMonthNames, $LongMonthNames;
1638      var $WeekDays, $Months;
1639      var $ShortWeekDayNames, $LongWeekDayNames;
1640  
1641      var $TimeArray;
1642      var $DateArray;
1643      var $TimePHPArray;
1644      var $DatePHPArray;
1645      //@}
1646  
1647      //@{
1648      /// Objects
1649      var $Country;
1650      var $CountryCode;
1651      var $CountryVariation;
1652      var $CountryComment;
1653      var $LanguageComment;
1654      var $LocaleINI;
1655      var $CountryINI;
1656      var $LanguageINI;
1657      /// The language code, for instance nor-NO, or eng-GB
1658      var $LanguageCode;
1659      /// Name of the language
1660      var $LanguageName;
1661      /// Internationalized name of the language
1662      var $IntlLanguageName;
1663      var $CountryNames;
1664      //@}
1665  };
1666  
1667  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7