system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.cubrid system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.gii system.i18n system.i18n.gettext system.logging system.test system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.form system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers zii.behaviors zii.widgets zii.widgets.grid zii.widgets.jui

CLocale

system.i18n
继承 class CLocale » CComponent
可用自 1.0
源码 framework/i18n/CLocale.php
CLocale represents the data relevant to a locale.

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

公共属性

隐藏继承的属性

属性类型描述被定义在
aMName string the AM name CLocale
currencyFormat string the currency format CLocale
dataPath string the directory that contains the locale data. 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
localeDisplayName string Gets a localized name from i18n data file (one of framework/i18n/data/ files). CLocale
monthNames array Returns the month names in the specified width. CLocale
numberFormatter CNumberFormatter the number formatter for this locale CLocale
orientation string the character orientation, which is either 'ltr' (left-to-right) or 'rtl' (right-to-left) CLocale
pMName string the PM name CLocale
percentFormat string the percent format CLocale
pluralRules array plural forms expressions CLocale
scientificFormat string the scientific format CLocale
timeFormat string date format CLocale
weekDayNames array Returns the week day names in the specified width. CLocale

公共方法

隐藏继承的方法

方法描述被定义在
__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
evaluateExpression() Evaluates a PHP expression or callback under the context of 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
getLanguage() Returns the local display name for the language. Null if the language code does not exist. CLocale
getLanguageID() Converts a locale ID to a language ID. CLocale
getLocaleDisplayName() Gets a localized name from i18n data file (one of framework/i18n/data/ files). 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
getOrientation() Returns the character orientation, which is either 'ltr' (left-to-right) or 'rtl' (right-to-left) CLocale
getPMName() Returns the PM name CLocale
getPercentFormat() Returns the percent format CLocale
getPluralRules() Returns plural forms expressions CLocale
getScientificFormat() Returns the scientific format CLocale
getScript() Returns the local display name for the script. Null if the script code does not exist. CLocale
getScriptID() Converts a locale ID to a script ID. CLocale
getTerritory() Returns the local display name for the territory. Null if the territory code does not exist. CLocale
getTerritoryID() Converts a locale ID to a territory ID. 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

受保护的方法

隐藏继承的方法

方法描述被定义在
__construct() Constructor. CLocale

属性详情

aMName 属性 只读
public string getAMName()

the AM name

currencyFormat 属性 只读
public string getCurrencyFormat()

the currency format

dataPath 属性 (自版本 v1.1.0 可用)
public static string $dataPath;

the directory that contains the locale data. If this property is not set, the locale data will be loaded from 'framework/i18n/data'.

dateFormat 属性 只读
public string getDateFormat(string $width='medium')

date format

dateFormatter 属性 只读

the date formatter for this locale

dateTimeFormat 属性 只读
public string getDateTimeFormat()

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

decimalFormat 属性 只读
public string getDecimalFormat()

the decimal format

id 属性 只读
public string getId()

the locale ID (in canonical form)

localeDisplayName 属性 只读 (自版本 v1.1.9 可用)
public string getLocaleDisplayName(string $id=NULL, string $category='languages')

Gets a localized name from i18n data file (one of framework/i18n/data/ files).

monthNames 属性 只读
public array getMonthNames(string $width='wide', boolean $standAlone=false)

Returns the month names in the specified width.

numberFormatter 属性 只读

the number formatter for this locale

orientation 属性 只读 (自版本 v1.1.2 可用)
public string getOrientation()

the character orientation, which is either 'ltr' (left-to-right) or 'rtl' (right-to-left)

pMName 属性 只读
public string getPMName()

the PM name

percentFormat 属性 只读
public string getPercentFormat()

the percent format

pluralRules 属性 只读
public array getPluralRules()

plural forms expressions

scientificFormat 属性 只读
public string getScientificFormat()

the scientific format

timeFormat 属性 只读
public string getTimeFormat(string $width='medium')

date format

weekDayNames 属性 只读
public array getWeekDayNames(string $width='wide', boolean $standAlone=false)

Returns the week day names in the specified width.

方法详情

__construct() 方法
protected void __construct(string $id)
$id string the locale ID (e.g. en_US)
源码: framework/i18n/CLocale.php#97 (显示)
protected function __construct($id)
{
    
$this->_id=self::getCanonicalID($id);
    
$dataPath=self::$dataPath===null dirname(__FILE__).DIRECTORY_SEPARATOR.'data' self::$dataPath;
    
$dataFile=$dataPath.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() 方法
public string getAMName()
{return} string the AM name
源码: framework/i18n/CLocale.php#267 (显示)
public function getAMName()
{
    return 
$this->_data['amName'];
}

getCanonicalID() 方法
public static string getCanonicalID(string $id)
$id string the locale ID to be converted
{return} string the locale ID in canonical form
源码: framework/i18n/CLocale.php#114 (显示)
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() 方法
public string getCurrencyFormat()
{return} string the currency format
源码: framework/i18n/CLocale.php#176 (显示)
public function getCurrencyFormat()
{
    return 
$this->_data['currencyFormat'];
}

getCurrencySymbol() 方法
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.
源码: framework/i18n/CLocale.php#151 (显示)
public function getCurrencySymbol($currency)
{
    return isset(
$this->_data['currencySymbols'][$currency]) ? $this->_data['currencySymbols'][$currency] : null;
}

getDateFormat() 方法
public string getDateFormat(string $width='medium')
$width string date format width. It can be 'full', 'long', 'medium' or 'short'.
{return} string date format
源码: framework/i18n/CLocale.php#284 (显示)
public function getDateFormat($width='medium')
{
    return 
$this->_data['dateFormats'][$width];
}

getDateFormatter() 方法
public CDateFormatter getDateFormatter()
{return} CDateFormatter the date formatter for this locale
源码: framework/i18n/CLocale.php#140 (显示)
public function getDateFormatter()
{
    if(
$this->_dateFormatter===null)
        
$this->_dateFormatter=new CDateFormatter($this);
    return 
$this->_dateFormatter;
}

getDateTimeFormat() 方法
public string getDateTimeFormat()
{return} string datetime format, i.e., the order of date and time.
源码: framework/i18n/CLocale.php#301 (显示)
public function getDateTimeFormat()
{
    return 
$this->_data['dateTimeFormat'];
}

getDecimalFormat() 方法
public string getDecimalFormat()
{return} string the decimal format
源码: framework/i18n/CLocale.php#168 (显示)
public function getDecimalFormat()
{
    return 
$this->_data['decimalFormat'];
}

getEraName() 方法
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
源码: framework/i18n/CLocale.php#259 (显示)
public function getEraName($era,$width='wide')
{
    return 
$this->_data['eraNames'][$width][$era];
}

getId() 方法
public string getId()
{return} string the locale ID (in canonical form)
源码: framework/i18n/CLocale.php#122 (显示)
public function getId()
{
    return 
$this->_id;
}

getInstance() 方法
public static CLocale getInstance(string $id)
$id string the locale ID (e.g. en_US)
{return} CLocale the locale instance
源码: framework/i18n/CLocale.php#58 (显示)
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.

getLanguage() 方法 (自版本 v1.1.9 可用)
public string getLanguage(string $id)
$id string Unicode language identifier from IETF BCP 47. For example, the code "en_US" represents U.S. English and "en_GB" represents British English.
{return} string the local display name for the language. Null if the language code does not exist.
源码: framework/i18n/CLocale.php#447 (显示)
public function getLanguage($id)
{
    
$id $this->getLanguageID($id);
    return 
$this->getLocaleDisplayName($id'languages');
}

getLanguageID() 方法 (自版本 v1.1.9 可用)
public string getLanguageID(string $id)
$id string the locale ID to be converted
{return} string the language ID
源码: framework/i18n/CLocale.php#330 (显示)
public function getLanguageID($id)
{
    
// normalize id
    
$id $this->getCanonicalID($id);
    
// remove sub tags
    
if(($underscorePosition=strpos($id'_'))!== false)
    {
        
$id substr($id0$underscorePosition);
    }
    return 
$id;
}

Converts a locale ID to a language ID. A language ID consists of only the first group of letters before an underscore or dash.

getLocaleDisplayName() 方法 (自版本 v1.1.9 可用)
public string getLocaleDisplayName(string $id=NULL, string $category='languages')
$id string array key from an array named by $category.
$category string data category. One of 'languages', 'scripts' or 'territories'.
{return} string the localized name for the id specified. Null if data does not exist.
源码: framework/i18n/CLocale.php#418 (显示)
public function getLocaleDisplayName($id=null$category='languages')
{
    
$id $this->getCanonicalID($id);
    if ((
$category == 'languages') && (isset($this->_data[$category][$id])))
    {
        return 
$this->_data[$category][$id];
    }
    elseif ((
$category == 'scripts') && ($val=$this->getScriptID($id)) && (isset($this->_data[$category][$val])))
    {
        return 
$this->_data[$category][$val];
    }
    elseif ((
$category == 'territories') && ($val=$this->getTerritoryID($id)) && (isset($this->_data[$category][$val])))
    {
        return 
$this->_data[$category][$val];
    }
    elseif (isset(
$this->_data[$category][$id]))
    {
        return 
$this->_data[$category][$id];
    }
    else {
        return 
null;
    }
}

Gets a localized name from i18n data file (one of framework/i18n/data/ files).

getLocaleIDs() 方法
public static array getLocaleIDs()
{return} array IDs of the locales which the framework can recognize
源码: framework/i18n/CLocale.php#70 (显示)
public static function getLocaleIDs()
{
    static 
$locales;
    if(
$locales===null)
    {
        
$locales=array();
        
$dataPath=self::$dataPath===null dirname(__FILE__).DIRECTORY_SEPARATOR.'data' self::$dataPath;
        
$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() 方法
public string getMonthName(integer $month, string $width='wide', boolean $standAlone=false)
$month integer month (1-12)
$width string month name width. It can be 'wide', 'abbreviated' or 'narrow'.
$standAlone boolean whether the month name should be returned in stand-alone format
{return} string the month name
源码: framework/i18n/CLocale.php#203 (显示)
public function getMonthName($month,$width='wide',$standAlone=false)
{
    if(
$standAlone)
        return isset(
$this->_data['monthNamesSA'][$width][$month]) ? $this->_data['monthNamesSA'][$width][$month] : $this->_data['monthNames'][$width][$month];
    else
        return isset(
$this->_data['monthNames'][$width][$month]) ? $this->_data['monthNames'][$width][$month] : $this->_data['monthNamesSA'][$width][$month];
}

getMonthNames() 方法
public array getMonthNames(string $width='wide', boolean $standAlone=false)
$width string month name width. It can be 'wide', 'abbreviated' or 'narrow'.
$standAlone boolean whether the month names should be returned in stand-alone format
{return} array month names indexed by month values (1-12)
源码: framework/i18n/CLocale.php#217 (显示)
public function getMonthNames($width='wide',$standAlone=false)
{
    if(
$standAlone)
        return isset(
$this->_data['monthNamesSA'][$width]) ? $this->_data['monthNamesSA'][$width] : $this->_data['monthNames'][$width];
    else
        return isset(
$this->_data['monthNames'][$width]) ? $this->_data['monthNames'][$width] : $this->_data['monthNamesSA'][$width];
}

Returns the month names in the specified width.

getNumberFormatter() 方法
public CNumberFormatter getNumberFormatter()
{return} CNumberFormatter the number formatter for this locale
源码: framework/i18n/CLocale.php#130 (显示)
public function getNumberFormatter()
{
    if(
$this->_numberFormatter===null)
        
$this->_numberFormatter=new CNumberFormatter($this);
    return 
$this->_numberFormatter;
}

getNumberSymbol() 方法
public string getNumberSymbol(string $name)
$name string symbol name
{return} string symbol
源码: framework/i18n/CLocale.php#160 (显示)
public function getNumberSymbol($name)
{
    return isset(
$this->_data['numberSymbols'][$name]) ? $this->_data['numberSymbols'][$name] : null;
}

getOrientation() 方法 (自版本 v1.1.2 可用)
public string getOrientation()
{return} string the character orientation, which is either 'ltr' (left-to-right) or 'rtl' (right-to-left)
源码: framework/i18n/CLocale.php#310 (显示)
public function getOrientation()
{
    return isset(
$this->_data['orientation']) ? $this->_data['orientation'] : 'ltr';
}

getPMName() 方法
public string getPMName()
{return} string the PM name
源码: framework/i18n/CLocale.php#275 (显示)
public function getPMName()
{
    return 
$this->_data['pmName'];
}

getPercentFormat() 方法
public string getPercentFormat()
{return} string the percent format
源码: framework/i18n/CLocale.php#184 (显示)
public function getPercentFormat()
{
    return 
$this->_data['percentFormat'];
}

getPluralRules() 方法
public array getPluralRules()
{return} array plural forms expressions
源码: framework/i18n/CLocale.php#318 (显示)
public function getPluralRules()
{
    return isset(
$this->_data['pluralRules']) ? $this->_data['pluralRules'] : array(0=>'true');
}

getScientificFormat() 方法
public string getScientificFormat()
{return} string the scientific format
源码: framework/i18n/CLocale.php#192 (显示)
public function getScientificFormat()
{
    return 
$this->_data['scientificFormat'];
}

getScript() 方法 (自版本 v1.1.9 可用)
public string getScript(string $id)
$id string Unicode script identifier from IETF BCP 47. For example, the code "en_US" represents U.S. English and "en_GB" represents British English.
{return} string the local display name for the script. Null if the script code does not exist.
源码: framework/i18n/CLocale.php#458 (显示)
public function getScript($id)
{
    return 
$this->getLocaleDisplayName($id'scripts');
}

getScriptID() 方法 (自版本 v1.1.9 可用)
public string getScriptID(string $id)
$id string the locale ID to be converted
{return} string the script ID
源码: framework/i18n/CLocale.php#349 (显示)
public function getScriptID($id)
{
    
// normalize id
    
$id $this->getCanonicalID($id);
    
// find sub tags
    
if(($underscorePosition=strpos($id'_'))!==false)
    {
        
$subTag explode('_'$id);
        
// script sub tags can be distinguished from territory sub tags by length
        
if (strlen($subTag[1])===4)
        {
            
$id $subTag[1];
        }
        else
        {
            
$id null;
        }
    }
    else
    {
        
$id null;
    }
    return 
$id;
}

Converts a locale ID to a script ID. A script ID consists of only the last four characters after an underscore or dash.

getTerritory() 方法 (自版本 v1.1.9 可用)
public string getTerritory(string $id)
$id string Unicode territory identifier from IETF BCP 47. For example, the code "en_US" represents U.S. English and "en_GB" represents British English.
{return} string the local display name for the territory. Null if the territory code does not exist.
源码: framework/i18n/CLocale.php#468 (显示)
public function getTerritory($id)
{
    return 
$this->getLocaleDisplayName($id'territories');
}

getTerritoryID() 方法 (自版本 v1.1.9 可用)
public string getTerritoryID(string $id)
$id string the locale ID to be converted
{return} string the territory ID
源码: framework/i18n/CLocale.php#381 (显示)
public function getTerritoryID($id)
{
    
// normalize id
    
$id $this->getCanonicalID($id);
    
// find sub tags
    
if (($underscorePosition=strpos($id'_'))!== false)
    {
        
$subTag explode('_'$id);
        
// territory sub tags can be distinguished from script sub tags by length
        
if (isset($subTag[2]) && strlen($subTag[2])<4)
        {
            
$id $subTag[2];
        }
        elseif (
strlen($subTag[1])<4)
        {
            
$id $subTag[1];
        }
        else
        {
            
$id null;
        }
    }
    else
    {
        
$id null;
    }
    return 
$id;
}

Converts a locale ID to a territory ID. A territory ID consists of only the last two to three letter or digits after an underscore or dash.

getTimeFormat() 方法
public string getTimeFormat(string $width='medium')
$width string time format width. It can be 'full', 'long', 'medium' or 'short'.
{return} string date format
源码: framework/i18n/CLocale.php#293 (显示)
public function getTimeFormat($width='medium')
{
    return 
$this->_data['timeFormats'][$width];
}

getWeekDayName() 方法
public string getWeekDayName(integer $day, string $width='wide', boolean $standAlone=false)
$day integer weekday (0-7, 0 and 7 means Sunday)
$width string weekday name width. It can be 'wide', 'abbreviated' or 'narrow'.
$standAlone boolean whether the week day name should be returned in stand-alone format
{return} string the weekday name
源码: framework/i18n/CLocale.php#231 (显示)
public function getWeekDayName($day,$width='wide',$standAlone=false)
{
    
$day=$day%7;
    if(
$standAlone)
        return isset(
$this->_data['weekDayNamesSA'][$width][$day]) ? $this->_data['weekDayNamesSA'][$width][$day] : $this->_data['weekDayNames'][$width][$day];
    else
        return isset(
$this->_data['weekDayNames'][$width][$day]) ? $this->_data['weekDayNames'][$width][$day] : $this->_data['weekDayNamesSA'][$width][$day];
}

getWeekDayNames() 方法
public array getWeekDayNames(string $width='wide', boolean $standAlone=false)
$width string weekday name width. It can be 'wide', 'abbreviated' or 'narrow'.
$standAlone boolean whether the week day name should be returned in stand-alone format
{return} array the weekday names indexed by weekday values (0-6, 0 means Sunday, 1 Monday, etc.)
源码: framework/i18n/CLocale.php#246 (显示)
public function getWeekDayNames($width='wide',$standAlone=false)
{
    if(
$standAlone)
        return isset(
$this->_data['weekDayNamesSA'][$width]) ? $this->_data['weekDayNamesSA'][$width] : $this->_data['weekDayNames'][$width];
    else
        return isset(
$this->_data['weekDayNames'][$width]) ? $this->_data['weekDayNames'][$width] : $this->_data['weekDayNamesSA'][$width];
}

Returns the week day names in the specified width.