PageRenderTime 54ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/ezlocale/classes/ezlocale.php

https://github.com/StephanBoganskyXrow/ezpublish
PHP | 1726 lines | 1249 code | 110 blank | 367 comment | 77 complexity | 3a99b83fb3fb5b288dbe80b6d070b4fe MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file