summaryrefslogtreecommitdiff
path: root/framework/I18N/core/CultureInfo.php
diff options
context:
space:
mode:
Diffstat (limited to 'framework/I18N/core/CultureInfo.php')
-rw-r--r--framework/I18N/core/CultureInfo.php212
1 files changed, 106 insertions, 106 deletions
diff --git a/framework/I18N/core/CultureInfo.php b/framework/I18N/core/CultureInfo.php
index 299a8b16..bcf2f245 100644
--- a/framework/I18N/core/CultureInfo.php
+++ b/framework/I18N/core/CultureInfo.php
@@ -13,117 +13,117 @@
* {@link http://prado.sourceforge.net/}
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version $Revision: 1.6 $ $Date: 2005/12/16 05:26:17 $
+ * @version $Id$
* @package System.I18N.core
*/
-
+
/**
* CultureInfo class.
- *
- * Represents information about a specific culture including the
- * names of the culture, the calendar used, as well as access to
- * culture-specific objects that provide methods for common operations,
+ *
+ * Represents information about a specific culture including the
+ * names of the culture, the calendar used, as well as access to
+ * culture-specific objects that provide methods for common operations,
* such as formatting dates, numbers, and currency.
- *
- * The CultureInfo class holds culture-specific information, such as the
- * associated language, sublanguage, country/region, calendar, and cultural
- * conventions. This class also provides access to culture-specific
+ *
+ * The CultureInfo class holds culture-specific information, such as the
+ * associated language, sublanguage, country/region, calendar, and cultural
+ * conventions. This class also provides access to culture-specific
* instances of DateTimeFormatInfo and NumberFormatInfo. These objects
* contain the information required for culture-specific operations,
* such as formatting dates, numbers and currency.
- *
- * The culture names follow the format "<languagecode>_<country/regioncode>",
+ *
+ * The culture names follow the format "<languagecode>_<country/regioncode>",
* where <languagecode> is a lowercase two-letter code derived from ISO 639
- * codes. You can find a full list of the ISO-639 codes at
- * http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt
- *
- * The <country/regioncode2> is an uppercase two-letter code derived from
- * ISO 3166. A copy of ISO-3166 can be found at
+ * codes. You can find a full list of the ISO-639 codes at
+ * http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt
+ *
+ * The <country/regioncode2> is an uppercase two-letter code derived from
+ * ISO 3166. A copy of ISO-3166 can be found at
* http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html
*
- * For example, Australian English is "en_AU".
- *
+ * For example, Australian English is "en_AU".
+ *
* @author Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @version v1.0, last update on Sat Dec 04 13:41:46 EST 2004
+ * @version $Id$
* @package System.I18N.core
*/
class CultureInfo
{
/**
* ICU data filename extension.
- * @var string
+ * @var string
*/
private $dataFileExt = '.dat';
/**
* The ICU data array.
- * @var array
+ * @var array
*/
private $data = array();
/**
* The current culture.
- * @var string
+ * @var string
*/
private $culture;
/**
* Directory where the ICU data is stored.
- * @var string
+ * @var string
*/
private $dataDir;
/**
* A list of ICU date files loaded.
- * @var array
+ * @var array
*/
private $dataFiles = array();
/**
* The current date time format info.
- * @var DateTimeFormatInfo
+ * @var DateTimeFormatInfo
*/
private $dateTimeFormat;
/**
* The current number format info.
- * @var NumberFormatInfo
+ * @var NumberFormatInfo
*/
private $numberFormat;
-
+
/**
* A list of properties that are accessable/writable.
- * @var array
- */
+ * @var array
+ */
protected $properties = array();
/**
- * Culture type, all.
+ * Culture type, all.
* @see getCultures()
- * @var int
+ * @var int
*/
const ALL = 0;
/**
- * Culture type, neutral.
+ * Culture type, neutral.
* @see getCultures()
- * @var int
- */
+ * @var int
+ */
const NEUTRAL = 1;
-
+
/**
- * Culture type, specific.
+ * Culture type, specific.
* @see getCultures()
- * @var int
- */
+ * @var int
+ */
const SPECIFIC = 2;
/**
- * Display the culture name.
+ * Display the culture name.
* @return string the culture name.
* @see getName()
*/
- function __toString()
+ function __toString()
{
return $this->getName();
}
@@ -134,7 +134,7 @@ class CultureInfo
* as an attribute/property to retrieve the value.
* @return mixed
*/
- function __get($name)
+ function __get($name)
{
$getProperty = 'get'.$name;
if(in_array($getProperty, $this->properties))
@@ -142,33 +142,33 @@ class CultureInfo
else
throw new Exception('Property '.$name.' does not exists.');
}
-
+
/**
* Allow functions that begins with 'set' to be called directly
* as an attribute/property to set the value.
*/
- function __set($name, $value)
+ function __set($name, $value)
{
$setProperty = 'set'.$name;
if(in_array($setProperty, $this->properties))
$this->$setProperty($value);
else
throw new Exception('Property '.$name.' can not be set.');
- }
+ }
+
-
/**
- * Initializes a new instance of the CultureInfo class based on the
+ * Initializes a new instance of the CultureInfo class based on the
* culture specified by name. E.g. <code>new CultureInfo('en_AU');</cdoe>
- * The culture indentifier must be of the form
+ * The culture indentifier must be of the form
* "language_(country/region/variant)".
* @param string a culture name, e.g. "en_AU".
* @return return new CultureInfo.
*/
- function __construct($culture='en')
+ function __construct($culture='en')
{
- $this->properties = get_class_methods($this);
-
+ $this->properties = get_class_methods($this);
+
if(empty($culture))
$culture = 'en';
@@ -176,41 +176,41 @@ class CultureInfo
$this->dataFileExt = $this->fileExt();
$this->setCulture($culture);
-
+
$this->loadCultureData('root');
- $this->loadCultureData($culture);
+ $this->loadCultureData($culture);
}
-
+
/**
* Get the default directory for the ICU data.
* The default is the "data" directory for this class.
- * @return string directory containing the ICU data.
+ * @return string directory containing the ICU data.
*/
protected static function dataDir()
{
return dirname(__FILE__).'/data/';
}
-
+
/**
* Get the filename extension for ICU data. Default is ".dat".
- * @return string filename extension for ICU data.
+ * @return string filename extension for ICU data.
*/
protected static function fileExt()
{
return '.dat';
}
-
+
/**
* Determine if a given culture is valid. Simply checks that the
* culture data exists.
* @param string a culture
- * @return boolean true if valid, false otherwise.
+ * @return boolean true if valid, false otherwise.
*/
public function validCulture($culture)
{
if(preg_match('/^[a-z]{2}(_[A-Z]{2,5}){0,2}$/', $culture))
return is_file(self::dataDir().$culture.self::fileExt());
-
+
return false;
}
@@ -235,10 +235,10 @@ class CultureInfo
* @param string the culture identifier.
*/
protected function loadCultureData($culture)
- {
+ {
$file_parts = explode('_',$culture);
$current_part = $file_parts[0];
-
+
$files = array($current_part);
for($i = 1, $k = count($file_parts); $i < $k; ++$i)
@@ -257,29 +257,29 @@ class CultureInfo
if(in_array($filename, $this->dataFiles) === false)
{
array_unshift($this->dataFiles, $file);
-
+
$data = &$this->getData($filename);
$this->data[$file] = &$data;
-
+
if(isset($data['__ALIAS']))
$this->loadCultureData($data['__ALIAS'][0]);
unset($data);
}
- }
+ }
}
-
+
/**
* Get the data by unserializing the ICU data from disk.
* The data files are cached in a static variable inside
* this function.
* @param string the ICU data filename
- * @return array ICU data
+ * @return array ICU data
*/
protected function &getData($filename)
{
static $data = array();
static $files = array();
-
+
if(!in_array($filename, $files))
{
$data[$filename] = unserialize(file_get_contents($filename));
@@ -288,7 +288,7 @@ class CultureInfo
return $data[$filename];
}
-
+
/**
* Find the specific ICU data information from the data.
* The path to the specific ICU data is separated with a slash "/".
@@ -297,19 +297,19 @@ class CultureInfo
* Use merge=true to return the ICU including the parent culture.
* E.g. The currency data for a variant, say "en_AU" contains one
* entry, the currency for AUD, the other currency data are stored
- * in the "en" data file. Thus to retrieve all the data regarding
+ * in the "en" data file. Thus to retrieve all the data regarding
* currency for "en_AU", you need to use findInfo("Currencies,true);.
* @param string the data you want to find.
* @param boolean merge the data from its parents.
- * @return mixed the specific ICU data.
+ * @return mixed the specific ICU data.
*/
- protected function findInfo($path='/', $merge=false)
+ protected function findInfo($path='/', $merge=false)
{
$result = array();
foreach($this->dataFiles as $section)
- {
+ {
$info = $this->searchArray($this->data[$section], $path);
-
+
if($info)
{
if($merge)
@@ -321,7 +321,7 @@ class CultureInfo
return $result;
}
-
+
/**
* Search the array for a specific value using a path separated using
* slash "/" separated path. e.g to find $info['hello']['world'],
@@ -330,7 +330,7 @@ class CultureInfo
* @param string slash "/" separated array path.
* @return mixed the value array using the path
*/
- private function searchArray($info, $path='/')
+ private function searchArray($info, $path='/')
{
$index = explode('/',$path);
@@ -345,11 +345,11 @@ class CultureInfo
return $array[$value];
}
}
-
+
/**
- * Gets the culture name in the format
+ * Gets the culture name in the format
* "<languagecode2>_(country/regioncode2)".
- * @return string culture name.
+ * @return string culture name.
*/
function getName()
{
@@ -359,9 +359,9 @@ class CultureInfo
/**
* Gets the DateTimeFormatInfo that defines the culturally appropriate
* format of displaying dates and times.
- * @return DateTimeFormatInfo date time format information for the culture.
+ * @return DateTimeFormatInfo date time format information for the culture.
*/
- function getDateTimeFormat()
+ function getDateTimeFormat()
{
if(is_null($this->dateTimeFormat))
{
@@ -377,7 +377,7 @@ class CultureInfo
* Set the date time format information.
* @param DateTimeFormatInfo the new date time format info.
*/
- function setDateTimeFormat($dateTimeFormat)
+ function setDateTimeFormat($dateTimeFormat)
{
$this->dateTimeFormat = $dateTimeFormat;
}
@@ -386,7 +386,7 @@ class CultureInfo
* Gets the default calendar used by the culture, e.g. "gregorian".
* @return string the default calendar.
*/
- function getCalendar()
+ function getCalendar()
{
$info = $this->findInfo('calendar/default');
return $info[0];
@@ -414,7 +414,7 @@ class CultureInfo
* Gets the culture name in English.
* Returns <code>array('Language','Country');</code>
* 'Country' is omitted if the culture is neutral.
- * @return array array with language and country as elements.
+ * @return array array with language and country as elements.
*/
function getEnglishName()
{
@@ -427,7 +427,7 @@ class CultureInfo
if($region)
return $language[0].' ('.$region[0].')';
else
- return $language[0];
+ return $language[0];
}
/**
@@ -435,7 +435,7 @@ class CultureInfo
* Any changes to the invariant culture affects all other
* instances of the invariant culture.
* The invariant culture is assumed to be "en";
- * @return CultureInfo invariant culture info is "en".
+ * @return CultureInfo invariant culture info is "en".
*/
static function getInvariantCulture()
{
@@ -446,10 +446,10 @@ class CultureInfo
}
/**
- * Gets a value indicating whether the current CultureInfo
+ * Gets a value indicating whether the current CultureInfo
* represents a neutral culture. Returns true if the culture
* only contains two characters.
- * @return boolean true if culture is neutral, false otherwise.
+ * @return boolean true if culture is neutral, false otherwise.
*/
function getIsNeutralCulture()
{
@@ -459,7 +459,7 @@ class CultureInfo
/**
* Gets the NumberFormatInfo that defines the culturally appropriate
* format of displaying numbers, currency, and percentage.
- * @return NumberFormatInfo the number format info for current culture.
+ * @return NumberFormatInfo the number format info for current culture.
*/
function getNumberFormat()
{
@@ -471,7 +471,7 @@ class CultureInfo
$data = array( 'NumberElements'=>$elements,
'NumberPatterns'=>$patterns,
'Currencies' => $currencies);
-
+
$this->setNumberFormat(new NumberFormatInfo($data));
}
return $this->numberFormat;
@@ -487,9 +487,9 @@ class CultureInfo
}
/**
- * Gets the CultureInfo that represents the parent culture of the
+ * Gets the CultureInfo that represents the parent culture of the
* current CultureInfo
- * @return CultureInfo parent culture information.
+ * @return CultureInfo parent culture information.
*/
function getParent()
{
@@ -501,26 +501,26 @@ class CultureInfo
}
/**
- * Gets the list of supported cultures filtered by the specified
+ * Gets the list of supported cultures filtered by the specified
* culture type. This is an EXPENSIVE function, it needs to traverse
* a list of ICU files in the data directory.
* This function can be called statically.
* @param int culture type, CultureInfo::ALL, CultureInfo::NEUTRAL
* or CultureInfo::SPECIFIC.
- * @return array list of culture information available.
+ * @return array list of culture information available.
*/
static function getCultures($type=CultureInfo::ALL)
{
$dataDir = CultureInfo::dataDir();
$dataExt = CultureInfo::fileExt();
$dir = dir($dataDir);
-
+
$neutral = array();
$specific = array();
- while (false !== ($entry = $dir->read()))
+ while (false !== ($entry = $dir->read()))
{
- if(is_file($dataDir.$entry)
+ if(is_file($dataDir.$entry)
&& substr($entry,-4) == $dataExt
&& $entry != 'root'.$dataExt)
{
@@ -545,7 +545,7 @@ class CultureInfo
break;
case CultureInfo::SPECIFIC :
return $specific;
- break;
+ break;
}
}
@@ -554,7 +554,7 @@ class CultureInfo
* E.g. <code>array(0 => array('hello'), 1 => 'world');</code>
* becomes <code>array(0 => 'hello', 1 => 'world');</code>
* @param array with single elements arrays
- * @return array simplified array.
+ * @return array simplified array.
*/
private function simplify($array)
{
@@ -571,7 +571,7 @@ class CultureInfo
/**
* Get a list of countries in the language of the localized version.
- * @return array a list of localized country names.
+ * @return array a list of localized country names.
*/
function getCountries()
{
@@ -580,7 +580,7 @@ class CultureInfo
/**
* Get a list of currencies in the language of the localized version.
- * @return array a list of localized currencies.
+ * @return array a list of localized currencies.
*/
function getCurrencies()
{
@@ -589,7 +589,7 @@ class CultureInfo
/**
* Get a list of languages in the language of the localized version.
- * @return array list of localized language names.
+ * @return array list of localized language names.
*/
function getLanguages()
{
@@ -598,8 +598,8 @@ class CultureInfo
/**
* Get a list of scripts in the language of the localized version.
- * @return array list of localized script names.
- */
+ * @return array list of localized script names.
+ */
function getScripts()
{
return $this->simplify($this->findInfo('Scripts',true));
@@ -607,8 +607,8 @@ class CultureInfo
/**
* Get a list of timezones in the language of the localized version.
- * @return array list of localized timezones.
- */
+ * @return array list of localized timezones.
+ */
function getTimeZones()
{
return $this->simplify($this->findInfo('zoneStrings',true));