CLocale

优质
小牛编辑
123浏览
2023-12-01
所有包 | 属性 | 方法
system.i18n
继承class CLocale » CComponent
源自1.0
版本$Id: CLocale.php 3518 2011-12-28 23:31:29Z alexander.makarow $
源码framework/i18n/CLocale.php
CLocale代表一个区域的相关数据。

这些数据包括数字格式和日期格式信息。

公共属性

隐藏继承属性

属性类型描述定义在
aMNamestringAM名称CLocale
currencyFormatstring货币格式CLocale
dataPathstring目录包含着区域数据。 如果未设置此属性,区域数据将从‘framework/i18n/data’加载。CLocale
dateFormatstring日期格式CLocale
dateFormatterCDateFormatter返回这个区域的日期格式CLocale
dateTimeFormatstring日期时间格式,比如:日期和时间的顺序。CLocale
decimalFormatstring十进制格式CLocale
idstring区域ID(典型格式)CLocale
localeDisplayNamestring获取本地化i18数据文件在(framework/i18n/data/ files)。CLocale
monthNamesarray返回指定宽度的月份名称。CLocale
numberFormatterCNumberFormatter返回这个区域的数字格式CLocale
orientationstring文字方向,要么是‘ltr’(从左到右),要么是‘rtl’(从右到左)。CLocale
pMNamestringPM名称CLocale
percentFormatstring百分比格式CLocale
pluralRulesarray复数形式表达式CLocale
scientificFormatstring科学记数法格式CLocale
timeFormatstring日期格式CLocale
weekDayNamesarray返回指定宽度的星期名字。CLocale

公共方法

隐藏继承方法

方法描述定义在
__call()如果类中没有调的方法名,则调用这个方法。CComponent
__get()返回一个属性值、一个事件处理程序列表或一个行为名称。CComponent
__isset()检查一个属性是否为null。CComponent
__set()设置一个组件的属性值。CComponent
__unset()设置一个组件的属性为null。CComponent
asa()返回这个名字的行为对象。CComponent
attachBehavior()附加一个行为到组件。CComponent
attachBehaviors()附加一个行为列表到组件。CComponent
attachEventHandler()为事件附加一个事件处理程序。CComponent
canGetProperty()确定属性是否可读。CComponent
canSetProperty()确定属性是否可写。CComponent
detachBehavior()从组件中分离一个行为。CComponent
detachBehaviors()从组件中分离所有行为。CComponent
detachEventHandler()分离一个存在的事件处理程序。CComponent
disableBehavior()禁用一个附加行为。CComponent
disableBehaviors()禁用组件附加的所有行为。CComponent
enableBehavior()启用一个附加行为。CComponent
enableBehaviors()启用组件附加的所有行为。CComponent
evaluateExpression()计算一个PHP表达式,或根据组件上下文执行回调。CComponent
getAMName()返回AM名称CLocale
getCanonicalID()转换区域ID为典型格式。CLocale
getCurrencyFormat()返回货币格式CLocale
getCurrencySymbol()返回该区域的货币符号,如果符号不存在则返回null。CLocale
getDateFormat()返回日期格式CLocale
getDateFormatter()返回返回这个区域的日期格式CLocale
getDateTimeFormat()返回日期时间格式,比如:日期和时间的顺序。CLocale
getDecimalFormat()返回十进制格式CLocale
getEraName()返回年代名称CLocale
getEventHandlers()返回一个事件的附加处理程序列表。CComponent
getId()返回区域ID(典型格式)CLocale
getInstance()返回指定区域实例。CLocale
getLanguage()返回显示本地化语言名称,如果不存在返回null。CLocale
getLanguageID()转换区域ID为语言ID。CLocale
getLocaleDisplayName()获取本地化i18数据文件在(framework/i18n/data/ files)。CLocale
getLocaleIDs()返回框架可以识别的区域ID。CLocale
getMonthName()返回月份名称CLocale
getMonthNames()返回指定宽度的月份名称。CLocale
getNumberFormatter()返回返回这个区域的数字格式CLocale
getNumberSymbol()返回符号CLocale
getOrientation()返回文字方向,要么是‘ltr’(从左到右),要么是‘rtl’(从右到左)。CLocale
getPMName()返回PM名称CLocale
getPercentFormat()返回百分比格式CLocale
getPluralRules()返回复数形式表达式CLocale
getScientificFormat()返回科学记数法格式CLocale
getScript()返回显示本地化脚本名称,如果不存在返回null。CLocale
getScriptID()转换区域ID为脚本ID。CLocale
getTerritory()返回显示范围名称,如果不存在返回null。CLocale
getTerritoryID()转换区域ID为范围ID。CLocale
getTimeFormat()返回日期格式CLocale
getWeekDayName()返回星期名称CLocale
getWeekDayNames()返回指定宽度的星期名字。CLocale
hasEvent()确定一个事件是否定义。CComponent
hasEventHandler()检查事件是否有附加的处理程序。CComponent
hasProperty()确定属性是否被定义。CComponent
raiseEvent()发起一个事件。CComponent

受保护方法

隐藏继承方法

方法描述定义在
__construct()构造函数。CLocale

属性详细

aMName 属性 只读 public string getAMName()

AM名称

currencyFormat 属性 只读 public string getCurrencyFormat()

货币格式

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

目录包含着区域数据。 如果未设置此属性,区域数据将从‘framework/i18n/data’加载。

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

日期格式

dateFormatter 属性 只读 public CDateFormatter getDateFormatter()

返回这个区域的日期格式

dateTimeFormat 属性 只读 public string getDateTimeFormat()

日期时间格式,比如:日期和时间的顺序。

decimalFormat 属性 只读 public string getDecimalFormat()

十进制格式

id 属性 只读 public string getId()

区域ID(典型格式)

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

获取本地化i18数据文件在(framework/i18n/data/ files)。

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

返回指定宽度的月份名称。

numberFormatter 属性 只读 public CNumberFormatter getNumberFormatter()

返回这个区域的数字格式

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

文字方向,要么是‘ltr’(从左到右),要么是‘rtl’(从右到左)。

pMName 属性 只读 public string getPMName()

PM名称

percentFormat 属性 只读 public string getPercentFormat()

百分比格式

pluralRules 属性 只读 public array getPluralRules()

复数形式表达式

scientificFormat 属性 只读 public string getScientificFormat()

科学记数法格式

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

日期格式

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

返回指定宽度的星期名字。

方法详细

__construct() 方法
protected void __construct(string $id)
$idstring区域ID(例如:en_US)
源码: framework/i18n/CLocale.php#97 (显示) protectedfunction__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
thrownewCException(Yii::t('yii','Unrecognizedlocale"{locale}".',array('{locale}'=>$id)));
}

构造函数。 由于构造方法受保护, 请使用getInstance来获得指定区域的实例。

getAMName() 方法
public string getAMName()
{return}stringAM名称
源码: framework/i18n/CLocale.php#266 (显示) publicfunctiongetAMName()
{
return$this->_data['amName'];
}
getCanonicalID() 方法
public static string getCanonicalID(string $id)
$idstring要转移的区域ID
{return}string返回区域ID的典型格式
源码: framework/i18n/CLocale.php#114 (显示) publicstaticfunctiongetCanonicalID($id)
{
returnstrtolower(str_replace('-','_',$id));
}

转换区域ID为典型格式。 在典型格式中,区域ID只能由小写字母和下划线组成。

getCurrencyFormat() 方法
public string getCurrencyFormat()
{return}string货币格式
源码: framework/i18n/CLocale.php#176 (显示) publicfunctiongetCurrencyFormat()
{
return$this->_data['currencyFormat'];
}
getCurrencySymbol() 方法
public string getCurrencySymbol(string $currency)
$currencystring3个字母的ISO4217码。比如:“USD”代表美元,“EUR”代表欧元。
{return}string该区域的货币符号,如果符号不存在则返回null。
源码: framework/i18n/CLocale.php#151 (显示) publicfunctiongetCurrencySymbol($currency)
{
returnisset($this->_data['currencySymbols'][$currency])?$this->_data['currencySymbols'][$currency]:null;
}
getDateFormat() 方法
public string getDateFormat(string $width='medium')
$widthstring日期格式宽度。可以是‘full’,‘long’,‘medium’或‘short’。
{return}string日期格式
源码: framework/i18n/CLocale.php#283 (显示) publicfunctiongetDateFormat($width='medium')
{
return$this->_data['dateFormats'][$width];
}
getDateFormatter() 方法
public CDateFormatter getDateFormatter()
{return}CDateFormatter返回这个区域的日期格式
源码: framework/i18n/CLocale.php#140 (显示) publicfunctiongetDateFormatter()
{
if($this->_dateFormatter===null)
$this->_dateFormatter=newCDateFormatter($this);
return$this->_dateFormatter;
}
getDateTimeFormat() 方法
public string getDateTimeFormat()
{return}string日期时间格式,比如:日期和时间的顺序。
源码: framework/i18n/CLocale.php#300 (显示) publicfunctiongetDateTimeFormat()
{
return$this->_data['dateTimeFormat'];
}
getDecimalFormat() 方法
public string getDecimalFormat()
{return}string十进制格式
源码: framework/i18n/CLocale.php#168 (显示) publicfunctiongetDecimalFormat()
{
return$this->_data['decimalFormat'];
}
getEraName() 方法
public string getEraName(integer $era, string $width='wide')
$erainteger年代(0,1)
$widthstring年代名称宽度。它可以是‘wide’,‘abbreviated’或‘narrow’。
{return}string年代名称
源码: framework/i18n/CLocale.php#258 (显示) publicfunctiongetEraName($era,$width='wide')
{
return$this->_data['eraNames'][$width][$era];
}
getId() 方法
public string getId()
{return}string区域ID(典型格式)
源码: framework/i18n/CLocale.php#122 (显示) publicfunctiongetId()
{
return$this->_id;
}
getInstance() 方法
public static CLocale getInstance(string $id)
$idstring区域ID(例如:en_US)
{return}CLocale返回区域实例
源码: framework/i18n/CLocale.php#59 (显示) publicstaticfunctiongetInstance($id)
{
static$locales=array();
if(isset($locales[$id]))
return$locales[$id];
else
return$locales[$id]=newCLocale($id);
}

返回指定区域实例。 由于CLocale的构造方法是受保护的, 你只可以使用这个方法来取得指定区域的实例。

getLanguage() 方法 (可用自 v1.1.9)
public string getLanguage(string $id)
$idstringUnicode语言标识符IETF BCP 47。 例如:代码“en_US”英语(美国)和“en_GB”代表英语(英国)。
{return}string显示本地化语言名称,如果不存在返回null。
源码: framework/i18n/CLocale.php#442 (显示) publicfunctiongetLanguage($id)
{
return$this->getLocaleDisplayName($id,'languages');
}
getLanguageID() 方法 (可用自 v1.1.9)
public string getLanguageID(string $id)
$idstring要转换的区域ID
{return}string语言ID
源码: framework/i18n/CLocale.php#329 (显示) publicfunctiongetLanguageID($id)
{
//normalizeid
$id=$this->getCanonicalID($id);
//removesubtags
if(($underscorePosition=strpos($id,'_'))!==false)
{
$id=substr($id,0,$underscorePosition);
}
return$id;
}

转换区域ID为语言ID。 语言ID为下划线前的一组字母。

getLocaleDisplayName() 方法 (可用自 v1.1.9)
public string getLocaleDisplayName(string $id=NULL, string $category='languages')
$idstringarray key from an array named by $category。
$categorystring数据类别。单一的‘languages’,‘scripts’或‘territories’。
{return}string返回指定的本地化名称,如果不存在则返回null。
源码: framework/i18n/CLocale.php#413 (显示) publicfunctiongetLocaleDisplayName($id=null,$category='languages')
{
$id=$this->getCanonicalID($id);
if(isset($this->_data[$category][$id]))
{
return$this->_data[$category][$id];
}
elseif(($category=='languages')&&($id=$this->getLanguageID($id))&&(isset($this->_data[$category][$id])))
{
return$this->_data[$category][$id];
}
elseif(($category=='scripts')&&($id=$this->getScriptID($id))&&(isset($this->_data[$category][$id])))
{
return$this->_data[$category][$id];
}
elseif(($category=='territories')&&($id=$this->getTerritoryID($id))&&(isset($this->_data[$category][$id])))
{
return$this->_data[$category][$id];
}
else{
returnnull;
}
}

获取本地化i18数据文件在(framework/i18n/data/ files)。

getLocaleIDs() 方法
public static array getLocaleIDs()
{return}array框架可以识别的区域ID。
源码: framework/i18n/CLocale.php#71 (显示) publicstaticfunctiongetLocaleIDs()
{
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)
$monthinteger月份(1-12)
$widthstring月份名称宽度,它可以是‘wide’,‘abbreviated’或‘narrow’。
$standAloneboolean是否返回独立格式的月份名称
{return}string月份名称
源码: framework/i18n/CLocale.php#203 (显示) publicfunctiongetMonthName($month,$width='wide',$standAlone=false)
{
if($standAlone)
returnisset($this->_data['monthNamesSA'][$width][$month])?$this->_data['monthNamesSA'][$width][$month]:$this->_data['monthNames'][$width][$month];
else
returnisset($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)
$widthstring月份名称宽度,它可以是‘wide’,‘abbreviated’或‘narrow’。
$standAloneboolean是否返回独立格式的月份名称
{return}array返回由(1-12)索引的月份名称
源码: framework/i18n/CLocale.php#217 (显示) publicfunctiongetMonthNames($width='wide',$standAlone=false)
{
if($standAlone)
returnisset($this->_data['monthNamesSA'][$width])?$this->_data['monthNamesSA'][$width]:$this->_data['monthNames'][$width];
else
returnisset($this->_data['monthNames'][$width])?$this->_data['monthNames'][$width]:$this->_data['monthNamesSA'][$width];
}

返回指定宽度的月份名称。

getNumberFormatter() 方法
public CNumberFormatter getNumberFormatter()
{return}CNumberFormatter返回这个区域的数字格式
源码: framework/i18n/CLocale.php#130 (显示) publicfunctiongetNumberFormatter()
{
if($this->_numberFormatter===null)
$this->_numberFormatter=newCNumberFormatter($this);
return$this->_numberFormatter;
}
getNumberSymbol() 方法
public string getNumberSymbol(string $name)
$namestring符号名称
{return}string符号
源码: framework/i18n/CLocale.php#160 (显示) publicfunctiongetNumberSymbol($name)
{
returnisset($this->_data['numberSymbols'][$name])?$this->_data['numberSymbols'][$name]:null;
}
getOrientation() 方法 (可用自 v1.1.2)
public string getOrientation()
{return}string文字方向,要么是‘ltr’(从左到右),要么是‘rtl’(从右到左)。
源码: framework/i18n/CLocale.php#309 (显示) publicfunctiongetOrientation()
{
returnisset($this->_data['orientation'])?$this->_data['orientation']:'ltr';
}
getPMName() 方法
public string getPMName()
{return}stringPM名称
源码: framework/i18n/CLocale.php#274 (显示) publicfunctiongetPMName()
{
return$this->_data['pmName'];
}
getPercentFormat() 方法
public string getPercentFormat()
{return}string百分比格式
源码: framework/i18n/CLocale.php#184 (显示) publicfunctiongetPercentFormat()
{
return$this->_data['percentFormat'];
}
getPluralRules() 方法
public array getPluralRules()
{return}array复数形式表达式
源码: framework/i18n/CLocale.php#317 (显示) publicfunctiongetPluralRules()
{
returnisset($this->_data['pluralRules'])?$this->_data['pluralRules']:array();
}
getScientificFormat() 方法
public string getScientificFormat()
{return}string科学记数法格式
源码: framework/i18n/CLocale.php#192 (显示) publicfunctiongetScientificFormat()
{
return$this->_data['scientificFormat'];
}
getScript() 方法 (可用自 v1.1.9)
public string getScript(string $id)
$idstringUnicode脚本标识符IETF BCP 47。 例如:代码“en_US”英语(美国)和“en_GB”代表英语(英国)。
{return}string显示本地化脚本名称,如果不存在返回null。
源码: framework/i18n/CLocale.php#452 (显示) publicfunctiongetScript($id)
{
return$this->getLocaleDisplayName($id,'scripts');
}
getScriptID() 方法 (可用自 v1.1.9)
public string getScriptID(string $id)
$idstring要转换的区域ID
{return}string脚本ID
源码: framework/i18n/CLocale.php#348 (显示) publicfunctiongetScriptID($id)
{
//normalizeid
$id=$this->getCanonicalID($id);
//findsubtags
if(($underscorePosition=strpos($id,'_'))!==false)
{
$subTag=explode('_',$id);
//scriptsubtagscanbedistigusedfromterritorysubtagsbylength
if(strlen($subTag[1])===4)
{
$id=$subTag[1];
}
else
{
$id=null;
}
}
else
{
$id=null;
}
return$id;
}

转换区域ID为脚本ID。 脚本ID为下划线后四位字符组成。

getTerritory() 方法 (可用自 v1.1.9)
public string getTerritory(string $id)
$idstringUnicode范围标识符IETF BCP 47。 例如:代码“en_US”英语(美国)和“en_GB”代表英语(英国)。
{return}string显示范围名称,如果不存在返回null。
源码: framework/i18n/CLocale.php#462 (显示) publicfunctiongetTerritory($id)
{
return$this->getLocaleDisplayName($id,'territories');
}
getTerritoryID() 方法 (可用自 v1.1.9)
public string getTerritoryID(string $id)
$idstring要转换的区域ID
{return}string范围ID
源码: framework/i18n/CLocale.php#380 (显示) publicfunctiongetTerritoryID($id)
{
//normalizeid
$id=$this->getCanonicalID($id);
//findsubtags
if(($underscorePosition=strpos($id,'_'))!==false)
{
$subTag=explode('_',$id);
//territorysubtagscanbedistigusedfromscriptsubtagsbylength
if(strlen($subTag[1])<4)
{
$id=$subTag[1];
}
else
{
$id=null;
}
}
else
{
$id=null;
}
return$id;
}

转换区域ID为范围ID。 范围ID由下划线后2至3位字母和数字组成。

getTimeFormat() 方法
public string getTimeFormat(string $width='medium')
$widthstring时间格式宽度。可以是‘full’,‘long’,‘medium’或‘short’。
{return}string日期格式
源码: framework/i18n/CLocale.php#292 (显示) publicfunctiongetTimeFormat($width='medium')
{
return$this->_data['timeFormats'][$width];
}
getWeekDayName() 方法
public string getWeekDayName(integer $day, string $width='wide', boolean $standAlone=false)
$dayinteger星期(0-6,0意味着星期天)
$widthstring星期名称宽度。它可以是‘wide’,‘abbreviated’或‘narrow’。
$standAloneboolean是否返回独立格式的星期名称
{return}string星期名称
源码: framework/i18n/CLocale.php#231 (显示) publicfunctiongetWeekDayName($day,$width='wide',$standAlone=false)
{
if($standAlone)
returnisset($this->_data['weekDayNamesSA'][$width][$day])?$this->_data['weekDayNamesSA'][$width][$day]:$this->_data['weekDayNames'][$width][$day];
else
returnisset($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)
$widthstring星期名称宽度。它可以是‘wide’,‘abbreviated’或‘narrow’。
$standAloneboolean是否返回独立格式的星期名称
{return}array由星期值索引 (0-6,0是星期天,1是星期一, ...)的星期名字。
源码: framework/i18n/CLocale.php#245 (显示) publicfunctiongetWeekDayNames($width='wide',$standAlone=false)
{
if($standAlone)
returnisset($this->_data['weekDayNamesSA'][$width])?$this->_data['weekDayNamesSA'][$width]:$this->_data['weekDayNames'][$width];
else
returnisset($this->_data['weekDayNames'][$width])?$this->_data['weekDayNames'][$width]:$this->_data['weekDayNamesSA'][$width];
}

返回指定宽度的星期名字。