Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezlocale.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezlocale.php 9160 2002-02-06 13:43:20Z jhe $
5 //
6 // Definition of eZLocale class
7 //
8 // Created on: <07-Sep-2000 14:33:48 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
29
32
116 //include_once( "kernel/classes/INIFile.php" );
117
118 class eZLocale
119 {
125 function __construct( $iso="" )
126 {
127 $ini =& eZINI::instance( 'site.ini' );
128
129 if ( file_exists( "kernel/classes/locale/" . $iso . ".ini" ) )
130 {
131 $this->LocaleIni = new eZINI( "kernel/classes/locale/" . $iso . ".ini", false );
132 }
133 else
134 {
135 $this->LocaleIni = new eZINI( "kernel/classes/locale/en_GB.ini", false );
136 }
137
138 $this->LanguageISO =& $this->LocaleIni->variable( "RegionalSettings", "LanguageISO" );
139 $this->CurrencySymbol =& $this->LocaleIni->variable( "RegionalSettings", "CurrencySymbol" );
140 $this->DecimalSymbol =& $this->LocaleIni->variable( "RegionalSettings", "DecimalSymbol" );
141 $this->ThousandsSymbol =& $this->LocaleIni->variable( "RegionalSettings", "ThousandsSymbol" );
142 $this->FractDigits =& $this->LocaleIni->variable( "RegionalSettings", "FractDigits" );
143
144 $this->PositivePrefixCurrencySymbol =& $this->LocaleIni->variable( "RegionalSettings", "PositivePrefixCurrencySymbol" );
145 $this->NegativePrefixCurrencySymbol =& $this->LocaleIni->variable( "RegionalSettings", "NegativePrefixCurrencySymbol" );
146
147 $this->TimeFormat =& $this->LocaleIni->variable( "RegionalSettings", "TimeFormat" );
148 $this->ShortTimeFormat =& $this->LocaleIni->variable( "RegionalSettings", "ShortTimeFormat" );
149 $this->DateFormat =& $this->LocaleIni->variable( "RegionalSettings", "DateFormat" );
150 $this->ShortDateFormat =& $this->LocaleIni->variable( "RegionalSettings", "ShortDateFormat" );
151 $this->MondayFirst =& $this->LocaleIni->variable( "RegionalSettings", "MondayFirst" );
152
153 }
154
163 function &format( &$obj, $isShort = true )
164 {
165 $returnString = "<b>Locale error</b>: object or type not supported.";
166
167 // TODO: implement more options for the date and time format.
168 $objClass = strtolower( get_class( $obj ) );
169 switch ( $objClass )
170 {
171 case "ezdate" :
172 case "eztime" :
173 case "ezdatetime" :
174 {
175 if ( $isShort )
176 {
177 $date = $this->ShortDateFormat;
178 $time = $this->ShortTimeFormat;
179 }
180 else
181 {
182 $date = $this->DateFormat;
183 $time = $this->TimeFormat;
184 }
185
186 // ezdate or ezdatetime
187 if ( $objClass != "eztime" )
188 {
189 // d - day of the month, 2 digits with leading zeros; i.e. "01" to "31"
190 $date =& str_replace( "%d", "" . $this->addZero( $obj->day() ) . "", $date );
191
192 // j - day of the month without leading zeros; i.e. "1" to "31"
193 $date =& str_replace( "%j", "" . $obj->day() . "", $date );
194
195 // D - day of the week, textual, 3 letters; i.e. "Fri"
196 $date =& str_replace( "%D", "" .
197 $this->dayName( $obj->dayOfWeek( $this->mondayFirst() ) ) .
198 "", $date );
199
200 // E - day of the week, textual, long; i.e. "Friday"
201 $date =& str_replace( "%E", "" . $this->dayName(
202 $obj->dayOfWeek( $this->mondayFirst() ), false ) . "", $date );
203
204 // F - month, textual, long; i.e. "January"
205 $date =& str_replace( "%F", "" . $this->monthName( $obj->month(), false ) . "", $date );
206
207 // M - month, textual, 3 letters; i.e. "Jan"
208 $date =& str_replace( "%M", "" . $this->monthName( $obj->month() ) . "", $date );
209
210 // m - month; i.e. "01" to "12"
211 $date =& str_replace( "%m", "" . $this->addZero( $obj->month() ), $date );
212
213 // n - month without leading zeros; i.e. "1" to "12"
214 $date =& str_replace( "%n", "" . $obj->month(), $date );
215
216 // t - number of days in the given month; i.e. "28" to "31"
217 $date =& str_replace( "%t", "" . $obj->daysInMonth(), $date );
218
219 // Y - year, 4 digits; i.e. "1999"
220 $date =& str_replace( "%Y", "" . $obj->year(), $date );
221
222 // y - year, 2 digits; i.e. "99"
223 $date =& str_replace( "%y", "" . substr( $obj->year(), 2 ), $date );
224
225 $returnString =& $date;
226 }
227
228 // eztime or ezdatetime
229 if ( $objClass != "ezdate" )
230 {
231 // a - "am" or "pm"
232 $time =& str_replace( "%a", "" . $this->ampm( $obj->hour(), false ) . "", $time );
233
234 // A - "AM" or "PM"
235 $time =& str_replace( "%A", "" . $this->ampm( $obj->hour(), true ) . "", $time );
236
237 // g - hour, 12-hour format without leading zeros; i.e. "1" to "12"
238 $time =& str_replace( "%g", "" . $this->twelveHour( $obj->hour() ) . "", $time );
239
240 // h - hour, 12-hour format; i.e. "01" to "12"
241 $time =& str_replace( "%h", "" . $this->addZero( $this->twelveHour( $obj->hour() ) )
242 . "", $time );
243
244 // G - hour, 24-hour format without leading zeros; i.e. "0" to "23"
245 $time =& str_replace( "%G", "" . $obj->hour() . "", $time );
246
247 // H - hour, 24-hour format; i.e. "00" to "23"
248 $time =& str_replace( "%H", "" . $this->addZero( $obj->hour() ) . "", $time );
249
250 // i - minutes; i.e. "00" to "59"
251 $time =& str_replace( "%i", "" . $this->addZero( $obj->minute() ) . "", $time );
252
253 // s - seconds; i.e. "00" to "59"
254 $time =& str_replace( "%s", "" . $this->addZero( $obj->second() ) . "", $time );
255
256 $returnString =& $time;
257 }
258
259 if ( $objClass == "ezdatetime" )
260 {
261 $returnString = $date . " " . $time;
262 }
263
264 break;
265 }
266
267 case "ezcurrency" :
268 {
269 $value = $obj->value();
270
271 $value =& number_format( $value, $this->FractDigits, $this->DecimalSymbol, $this->ThousandsSymbol );
272
273 if ( $obj->isNegative() )
274 {
275 if ( $this->NegativePrefixCurrencySymbol == "yes" )
276 {
277 $value = "-&nbsp;" . $this->CurrencySymbol . "&nbsp;" . $value;
278 }
279 else
280 {
281 $value = "-&nbsp;" . $value . "&nbsp;" . $this->CurrencySymbol;
282 }
283 }
284 else
285 {
286 if ( $this->PositivePrefixCurrencySymbol == "yes" )
287 {
288 $value = $this->CurrencySymbol . "&nbsp;" . $value;
289 }
290 else
291 {
292 $value = $value . "&nbsp;" . $this->CurrencySymbol;
293 }
294 }
295
296 $returnString =& $value;
297
298
299
300 break;
301 }
302 }
303 return $returnString;
304 }
305
314 function &dayName( $day, $isShort=true )
315 {
316 $errorString = "<b>Locale error</b>: unknown day name";
317 $name = "";
318
319 if ( $day == "unknown" )
320 return $errorString;
321
322 if ( $isShort )
323 $long = "";
324 else
325 $long = "long";
326
327 if ( is_numeric( $day ) == true )
328 {
329 switch ( $day )
330 {
331 case 1 :
332 {
333 $day = ( $this->mondayFirst() ) ? "mon" : "sun";
334 break;
335 }
336 case 2 :
337 {
338 $day = ( $this->mondayFirst() ) ? "tue" : "mon";
339 break;
340 }
341 case 3 :
342 {
343 $day = ( $this->mondayFirst() ) ? "wed" : "tue";
344 break;
345 }
346 case 4 :
347 {
348 $day = ( $this->mondayFirst() ) ? "thu" : "wed";
349 break;
350 }
351 case 5 :
352 {
353 $day = ( $this->mondayFirst() ) ? "fri" : "thu";
354 break;
355 }
356 case 6 :
357 {
358 $day = ( $this->mondayFirst() ) ? "sat" : "fri";
359 break;
360 }
361 case 7 :
362 {
363 $day = ( $this->mondayFirst() ) ? "sun" : "sat";
364 break;
365 }
366 }
367 }
368
369 $name =& $this->LocaleIni->variable( "RegionalSettings", $long . $day );
370
371 if ( $name )
372 {
373 return $name;
374 }
375 else
376 {
377 return $errorString;
378 }
379 }
380
389 function &monthName( $month, $isShort=true )
390 {
391 $errorString = "<b>Locale error</b>: unknown month name";
392 $name = "";
393
394 if ( $month == "unknown" )
395 return $errorString;
396
397 if ( $isShort )
398 $long = "";
399 else
400 $long = "long";
401
402 if ( is_numeric( $month ) == true )
403 {
404 switch ( $month )
405 {
406 case 1 :
407 {
408 $month = "jan";
409 break;
410 }
411 case 2 :
412 {
413 $month = "feb";
414 break;
415 }
416 case 3 :
417 {
418 $month = "mar";
419 break;
420 }
421 case 4 :
422 {
423 $month = "apr";
424 break;
425 }
426 case 5 :
427 {
428 $month = "may";
429 break;
430 }
431 case 6 :
432 {
433 $month = "jun";
434 break;
435 }
436 case 7 :
437 {
438 $month = "jul";
439 break;
440 }
441 case 8 :
442 {
443 $month = "aug";
444 break;
445 }
446 case 9 :
447 {
448 $month = "sep";
449 break;
450 }
451 case 10 :
452 {
453 $month = "oct";
454 break;
455 }
456 case 11 :
457 {
458 $month = "nov";
459 break;
460 }
461 case 12 :
462 {
463 $month = "dec";
464 break;
465 }
466 }
467 }
468
469 $name =& $this->LocaleIni->variable( "RegionalSettings", $long . $month );
470
471 if ( $name == false )
472 {
473 return $errorString;
474 }
475 else
476 {
477 return $name;
478 }
479 }
480
481 function formatNumber( $value )
482 {
483 if ( is_numeric( $value ) )
484 {
485 if ( $value == round( $value ) )
486 $value =& number_format( $value, 0, $this->DecimalSymbol, $this->ThousandsSymbol );
487 else
488 $value =& number_format( $value, $this->FractDigits, $this->DecimalSymbol, $this->ThousandsSymbol );
489 }
490 return $value;
491 }
492
496 function mondayFirst()
497 {
498 if ( $this->MondayFirst == "yes" )
499 {
500 return true;
501 }
502 else
503 {
504 return false;
505 }
506 }
507
512 function languageISO()
513 {
514 if ( $this->LanguageISO != "" )
515 return $this->LanguageISO;
516 else
517 return false;
518 }
519
524 public static function addZero( $value )
525 {
526 $ret = $value;
527 if ( $ret < 10 )
528 {
529 $ret = "0". $ret;
530 }
531
532 return $ret;
533 }
534
538 function setSymbol( $value )
539 {
540 $this->CurrencySymbol = $value;
541 }
542
546 function setPrefixSymbol( $value )
547 {
548 if ( $value == true )
549 {
550 $this->PositivePrefixCurrencySymbol = "yes";
551 $this->NegativePrefixCurrencySymbol = "yes";
552 }
553 else
554 {
555 $this->PositivePrefixCurrencySymbol = "no";
556 $this->NegativePrefixCurrencySymbol = "no";
557 }
558 }
559
565 function ampm( $hour, $uppercase = true )
566 {
567 if ( $hour < 12 )
568 $ret = "AM";
569 else
570 $ret = "PM";
571
572 if ( $uppercase == false )
573 return strtolower( $ret );
574 else
575 return $ret;
576 }
577
582 function twelveHour( $hour )
583 {
584 if ( $hour == 0 )
585 return 12;
586 else if ( $hour > 12 )
587 return $hour % 12;
588 else
589 return $hour;
590 }
591
592
593 var $PositivePrefixCurrencySymbol;
594 var $NegativePrefixCurrencySymbol;
595
596 var $LanguageISO;
597 var $CurrencySymbol;
598 var $DecimalSymbol;
599 var $ThousandsSymbol;
600 var $FractDigits;
601 var $TimeFormat;
602 var $ShortTimeFormat;
603 var $DateFormat;
604 var $ShortDateFormat;
605 var $MondayFirst;
606
607 var $LocaleIni;
608 }
609
610
611 ?>
$day
else $day
Definition: appointmentedit.php:665
$month
else $month
Definition: appointmentedit.php:660
$date
$date
Definition: bugpreview.php:66
eZINI
Reads and writes .ini style configuration files.
eZLocale
Definition: ezlocale.php:119
eZLocale\format
& format(&$obj, $isShort=true)
Definition: ezlocale.php:163
eZLocale\$DateFormat
$DateFormat
Definition: ezlocale.php:603
eZLocale\$FractDigits
$FractDigits
Definition: ezlocale.php:600
eZLocale\ampm
ampm( $hour, $uppercase=true)
Definition: ezlocale.php:565
eZLocale\$DecimalSymbol
$DecimalSymbol
Definition: ezlocale.php:598
eZLocale\monthName
& monthName( $month, $isShort=true)
Definition: ezlocale.php:389
eZLocale\__construct
__construct( $iso="")
Definition: ezlocale.php:125
eZLocale\$TimeFormat
$TimeFormat
Definition: ezlocale.php:601
eZLocale\setPrefixSymbol
setPrefixSymbol( $value)
Definition: ezlocale.php:546
eZLocale\mondayFirst
mondayFirst()
Definition: ezlocale.php:496
eZLocale\$NegativePrefixCurrencySymbol
$NegativePrefixCurrencySymbol
Definition: ezlocale.php:594
eZLocale\addZero
static addZero( $value)
Definition: ezlocale.php:524
eZLocale\$LanguageISO
$LanguageISO
Definition: ezlocale.php:596
eZLocale\twelveHour
twelveHour( $hour)
Definition: ezlocale.php:582
eZLocale\setSymbol
setSymbol( $value)
Definition: ezlocale.php:538
eZLocale\$ShortDateFormat
$ShortDateFormat
Definition: ezlocale.php:604
eZLocale\languageISO
languageISO()
Definition: ezlocale.php:512
eZLocale\$MondayFirst
$MondayFirst
Definition: ezlocale.php:605
eZLocale\$ShortTimeFormat
$ShortTimeFormat
Definition: ezlocale.php:602
eZLocale\$ThousandsSymbol
$ThousandsSymbol
Definition: ezlocale.php:599
eZLocale\$CurrencySymbol
$CurrencySymbol
Definition: ezlocale.php:597
eZLocale\$LocaleIni
$LocaleIni
Definition: ezlocale.php:607
eZLocale\$PositivePrefixCurrencySymbol
$PositivePrefixCurrencySymbol
Definition: ezlocale.php:593
eZLocale\dayName
& dayName( $day, $isShort=true)
Definition: ezlocale.php:314
eZLocale\formatNumber
formatNumber( $value)
Definition: ezlocale.php:481
$ini
$ini
Definition: classes/admin/linklist.php:64
$name
$name
Definition: companytypelist.php:194
file_exists
static file_exists( $inifilename)
Definition: eZPBINIFile.php:195
$hour
$hour
Definition: export_froogle.php:310
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$time
$time
Definition: homepage.php:327
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.