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
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 "_",
where 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 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".
/** * Gets the default NumberFormatInfo that is culture-independent * (invariant). * @return NumberFormatInfo default NumberFormatInfo. */ public static function getInvariantInfo($type = NumberFormatInfo::DECIMAL) { static $invariant; if ($invariant === null) { $culture = CultureInfo::getInvariantCulture(); $invariant = $culture->NumberFormat; $invariant->setPattern($type); } return $invariant; }
function test_missing_english_names_returns_culture_code() { $culture = new CultureInfo('iw'); $this->assertEquals($culture->getEnglishName(), 'iw'); }
/** * Returns the DateTimeFormatInfo associated with the specified culture. * @param CultureInfo the culture that gets the DateTimeFormat property. * @return DateTimeFormatInfo DateTimeFormatInfo for the specified * culture. */ static function getInstance($culture = null) { if ($culture instanceof CultureInfo) { return $culture->getDateTimeFormat(); } else { if (is_string($culture)) { $cultureInfo = CultureInfo::getInstance($culture); return $cultureInfo->getDateTimeFormat(); } else { $cultureInfo = CultureInfo::getInvariantCulture(); return $cultureInfo->getDateTimeFormat(); } } }
/** * 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. */ static function getCultures($type = CultureInfo::ALL) { $dataDir = CultureInfo::dataDir(); $dataExt = CultureInfo::fileExt(); $dir = dir($dataDir); $neutral = array(); $specific = array(); while (false !== ($entry = $dir->read())) { if (is_file($dataDir . $entry) && substr($entry, -4) == $dataExt && $entry != 'root' . $dataExt) { $culture = substr($entry, 0, -4); if (strlen($culture) == 2) { $neutral[] = $culture; } else { $specific[] = $culture; } } } $dir->close(); switch ($type) { case CultureInfo::ALL: $all = array_merge($neutral, $specific); sort($all); return $all; break; case CultureInfo::NEUTRAL: return $neutral; break; case CultureInfo::SPECIFIC: return $specific; break; } }
/** * @return DateTimeFormatInfo date time format information for the current culture. */ protected function getLocalizedCalendarInfo() { //expensive operations $culture = $this->getCurrentCulture(); $info = new CultureInfo($culture); return $info->getDateTimeFormat(); }