0 follower

CLocale

Package system.i18n
Inheritance class CLocale » CComponent
Since 1.0
Version $Id$
Source Code framework/i18n/CLocale.php
CLocale represents the data relevant to a locale.

The data includes the number formatting information and date formatting information.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
aMName string the AM name CLocale
currencyFormat string the currency format CLocale
dateFormat string date format CLocale
dateFormatter CDateFormatter the date formatter for this locale CLocale
dateTimeFormat string datetime format, i.e., the order of date and time. CLocale
decimalFormat string the decimal format CLocale
id string the locale ID (in canonical form) CLocale
monthNames array Returns the month names in the specified width. CLocale
numberFormatter CNumberFormatter the number formatter for this locale CLocale
pMName string the PM name CLocale
percentFormat string the percent format CLocale
scientificFormat string the scientific format CLocale
timeFormat string date format CLocale
weekDayNames array Returns the week day names in the specified width. CLocale

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. CComponent
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
getAMName() Returns the AM name CLocale
getCanonicalID() Converts a locale ID to its canonical form. CLocale
getCurrencyFormat() Returns the currency format CLocale
getCurrencySymbol() Returns the localized currency symbol. Null if the symbol does not exist. CLocale
getDateFormat() Returns date format CLocale
getDateFormatter() Returns the date formatter for this locale CLocale
getDateTimeFormat() Returns datetime format, i.e., the order of date and time. CLocale
getDecimalFormat() Returns the decimal format CLocale
getEraName() Returns the era name CLocale
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getId() Returns the locale ID (in canonical form) CLocale
getInstance() Returns the instance of the specified locale. CLocale
getLocaleIDs() Returns IDs of the locales which the framework can recognize CLocale
getMonthName() Returns the month name CLocale
getMonthNames() Returns the month names in the specified width. CLocale
getNumberFormatter() Returns the number formatter for this locale CLocale
getNumberSymbol() Returns symbol CLocale
getPMName() Returns the PM name CLocale
getPercentFormat() Returns the percent format CLocale
getScientificFormat() Returns the scientific format CLocale
getTimeFormat() Returns date format CLocale
getWeekDayName() Returns the weekday name CLocale
getWeekDayNames() Returns the week day names in the specified width. CLocale
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
raiseEvent() Raises an event. CComponent

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
__construct() Constructor. CLocale

Property Details

aMName property read-only
public string getAMName()

the AM name

currencyFormat property read-only
public string getCurrencyFormat()

the currency format

dateFormat property read-only
public string getDateFormat(string $width='medium')

date format

dateFormatter property read-only

the date formatter for this locale

dateTimeFormat property read-only
public string getDateTimeFormat()

datetime format, i.e., the order of date and time.

decimalFormat property read-only
public string getDecimalFormat()

the decimal format

id property read-only
public string getId()

the locale ID (in canonical form)

monthNames property read-only (available since v1.0.9)
public array getMonthNames(string $width='wide')

Returns the month names in the specified width.

numberFormatter property read-only

the number formatter for this locale

pMName property read-only
public string getPMName()

the PM name

percentFormat property read-only
public string getPercentFormat()

the percent format

scientificFormat property read-only
public string getScientificFormat()

the scientific format

timeFormat property read-only
public string getTimeFormat(string $width='medium')

date format

weekDayNames property read-only (available since v1.0.9)
public array getWeekDayNames(string $width='wide')

Returns the week day names in the specified width.

Method Details

__construct() method
protected void __construct(string $id)
$id string the locale ID (e.g. en_US)
Source Code: framework/i18n/CLocale.php#73 (show)
protected function __construct($id)
{
    
$this->_id=self::getCanonicalID($id);
    
$dataFile=dirname(__FILE__).DIRECTORY_SEPARATOR.'data'.DIRECTORY_SEPARATOR.$this->_id.'.php';
    if(
is_file($dataFile))
        
$this->_data=require($dataFile);
    else
        throw new 
CException(Yii::t('yii','Unrecognized locale "{locale}".',array('{locale}'=>$id)));
}

Constructor. Since the constructor is protected, please use getInstance to obtain an instance of the specified locale.

getAMName() method
public string getAMName()
{return} string the AM name
Source Code: framework/i18n/CLocale.php#227 (show)
public function getAMName()
{
    return 
$this->_data['amName'];
}

getCanonicalID() method
public static string getCanonicalID(string $id)
$id string the locale ID to be converted
{return} string the locale ID in canonical form
Source Code: framework/i18n/CLocale.php#89 (show)
public static function getCanonicalID($id)
{
    return 
strtolower(str_replace('-','_',$id));
}

Converts a locale ID to its canonical form. In canonical form, a locale ID consists of only underscores and lower-case letters.

getCurrencyFormat() method
public string getCurrencyFormat()
{return} string the currency format
Source Code: framework/i18n/CLocale.php#151 (show)
public function getCurrencyFormat()
{
    return 
$this->_data['currencyFormat'];
}

getCurrencySymbol() method
public string getCurrencySymbol(string $currency)
$currency string 3-letter ISO 4217 code. For example, the code "USD" represents the US Dollar and "EUR" represents the Euro currency.
{return} string the localized currency symbol. Null if the symbol does not exist.
Source Code: framework/i18n/CLocale.php#126 (show)
public function getCurrencySymbol($currency)
{
    return isset(
$this->_data['currencySymbols'][$currency]) ? $this->_data['currencySymbols'][$currency] : null;
}

getDateFormat() method
public string getDateFormat(string $width='medium')
$width string date format width. It can be 'full', 'long', 'medium' or 'short'.
{return} string date format
Source Code: framework/i18n/CLocale.php#244 (show)
public function getDateFormat($width='medium')
{
    return 
$this->_data['dateFormats'][$width];
}

getDateFormatter() method
public CDateFormatter getDateFormatter()
{return} CDateFormatter the date formatter for this locale
Source Code: framework/i18n/CLocale.php#115 (show)
public function getDateFormatter()
{
    if(
$this->_dateFormatter===null)
        
$this->_dateFormatter=new CDateFormatter($this);
    return 
$this->_dateFormatter;
}

getDateTimeFormat() method
public string getDateTimeFormat()
{return} string datetime format, i.e., the order of date and time.
Source Code: framework/i18n/CLocale.php#261 (show)
public function getDateTimeFormat()
{
    return 
$this->_data['dateTimeFormat'];
}

getDecimalFormat() method
public string getDecimalFormat()
{return} string the decimal format
Source Code: framework/i18n/CLocale.php#143 (show)
public function getDecimalFormat()
{
    return 
$this->_data['decimalFormat'];
}

getEraName() method
public string getEraName(integer $era, string $width='wide')
$era integer era (0,1)
$width string era name width. It can be 'wide', 'abbreviated' or 'narrow'.
{return} string the era name
Source Code: framework/i18n/CLocale.php#219 (show)
public function getEraName($era,$width='wide')
{
    return 
$this->_data['eraNames'][$width][$era];
}

getId() method
public string getId()
{return} string the locale ID (in canonical form)
Source Code: framework/i18n/CLocale.php#97 (show)
public function getId()
{
    return 
$this->_id;
}

getInstance() method
public static CLocale getInstance(string $id)
$id string the locale ID (e.g. en_US)
{return} CLocale the locale instance
Source Code: framework/i18n/CLocale.php#35 (show)
public static function getInstance($id)
{
    static 
$locales=array();
    if(isset(
$locales[$id]))
        return 
$locales[$id];
    else
        return 
$locales[$id]=new CLocale($id);
}

Returns the instance of the specified locale. Since the constructor of CLocale is protected, you can only use this method to obtain an instance of the specified locale.

getLocaleIDs() method
public static array getLocaleIDs()
{return} array IDs of the locales which the framework can recognize
Source Code: framework/i18n/CLocale.php#47 (show)
public static function getLocaleIDs()
{
    static 
$locales;
    if(
$locales===null)
    {
        
$locales=array();
        
$dataPath=dirname(__FILE__).DIRECTORY_SEPARATOR.'data';
        
$folder=@opendir($dataPath);
        while((
$file=@readdir($folder))!==false)
        {
            
$fullPath=$dataPath.DIRECTORY_SEPARATOR.$file;
            if(
substr($file,-4)==='.php' && is_file($fullPath))
                
$locales[]=substr($file,0,-4);
        }
        
closedir($folder);
        
sort($locales);
    }
    return 
$locales;
}

getMonthName() method
public string getMonthName(integer $month, string $width='wide')
$month integer month (1-12)
$width string month name width. It can be 'wide', 'abbreviated' or 'narrow'.
{return} string the month name
Source Code: framework/i18n/CLocale.php#177 (show)
public function getMonthName($month,$width='wide')
{
    return 
$this->_data['monthNames'][$width][$month];
}

getMonthNames() method (available since v1.0.9)
public array getMonthNames(string $width='wide')
$width string month name width. It can be 'wide', 'abbreviated' or 'narrow'.
{return} array month names indexed by month values (1-12)
Source Code: framework/i18n/CLocale.php#188 (show)
public function getMonthNames($width='wide')
{
    return 
$this->_data['monthNames'][$width];
}

Returns the month names in the specified width.

getNumberFormatter() method
public CNumberFormatter getNumberFormatter()
{return} CNumberFormatter the number formatter for this locale
Source Code: framework/i18n/CLocale.php#105 (show)
public function getNumberFormatter()
{
    if(
$this->_numberFormatter===null)
        
$this->_numberFormatter=new CNumberFormatter($this);
    return 
$this->_numberFormatter;
}

getNumberSymbol() method
public string getNumberSymbol(string $name)
$name string symbol name
{return} string symbol
Source Code: framework/i18n/CLocale.php#135 (show)
public function getNumberSymbol($name)
{
    return isset(
$this->_data['numberSymbols'][$name]) ? $this->_data['numberSymbols'][$name] : null;
}

getPMName() method
public string getPMName()
{return} string the PM name
Source Code: framework/i18n/CLocale.php#235 (show)
public function getPMName()
{
    return 
$this->_data['pmName'];
}

getPercentFormat() method
public string getPercentFormat()
{return} string the percent format
Source Code: framework/i18n/CLocale.php#159 (show)
public function getPercentFormat()
{
    return 
$this->_data['percentFormat'];
}

getScientificFormat() method
public string getScientificFormat()
{return} string the scientific format
Source Code: framework/i18n/CLocale.php#167 (show)
public function getScientificFormat()
{
    return 
$this->_data['scientificFormat'];
}

getTimeFormat() method
public string getTimeFormat(string $width='medium')
$width string time format width. It can be 'full', 'long', 'medium' or 'short'.
{return} string date format
Source Code: framework/i18n/CLocale.php#253 (show)
public function getTimeFormat($width='medium')
{
    return 
$this->_data['timeFormats'][$width];
}

getWeekDayName() method
public string getWeekDayName(integer $day, string $width='wide')
$day integer weekday (0-6, 0 means Sunday)
$width string weekday name width. It can be 'wide', 'abbreviated' or 'narrow'.
{return} string the weekday name
Source Code: framework/i18n/CLocale.php#198 (show)
public function getWeekDayName($day,$width='wide')
{
    return 
$this->_data['weekDayNames'][$width][$day];
}

getWeekDayNames() method (available since v1.0.9)
public array getWeekDayNames(string $width='wide')
$width string weekday name width. It can be 'wide', 'abbreviated' or 'narrow'.
{return} array the weekday names indexed by weekday values (0-6, 0 means Sunday, 1 Monday, etc.)
Source Code: framework/i18n/CLocale.php#209 (show)
public function getWeekDayNames($width='wide')
{
    return 
$this->_data['weekDayNames'][$width];
}

Returns the week day names in the specified width.