本文整理汇总了PHP中Zend\Locale\Locale::findLocale方法的典型用法代码示例。如果您正苦于以下问题:PHP Locale::findLocale方法的具体用法?PHP Locale::findLocale怎么用?PHP Locale::findLocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Locale\Locale
的用法示例。
在下文中一共展示了Locale::findLocale方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isDate
/**
* Checks if the given date is a real date or datepart.
* Returns false if a expected datepart is missing or a datepart exceeds its possible border.
* But the check will only be done for the expected dateparts which are given by format.
* If no format is given the standard dateformat for the actual locale is used.
* f.e. 30.February.2007 will return false if format is 'dd.MMMM.YYYY'
*
* @param string|array|\Zend\Date\Date $date Date to parse for correctness
* @param string $format (Optional) Format for parsing the date string
* @param string|\Zend\Locale\Locale $locale (Optional) Locale for parsing date parts
* @return boolean True when all date parts are correct
*/
public static function isDate($date, $format = null, $locale = null)
{
if (!is_string($date) && !is_numeric($date) && !$date instanceof Date && !is_array($date)) {
return false;
}
if ($format !== null && $format != 'ee' && $format != 'ss' && $format != 'GG' && $format != 'MM' && $format != 'EE' && $format != 'TT' && Locale::isLocale($format)) {
$locale = $format;
$format = null;
}
$locale = Locale::findLocale($locale);
if ($format === null) {
$format = Format::getDateFormat($locale);
} else {
if (self::$_options['format_type'] == 'php' && !defined($format)) {
$format = Format::convertPhpToIsoFormat($format);
}
}
$format = self::_getLocalizedToken($format, $locale);
if (!is_array($date)) {
try {
$parsed = Format::getDate($date, array('locale' => $locale, 'date_format' => $format, 'format_type' => 'iso', 'fix_date' => false));
} catch (\Zend\Locale\Exception $e) {
// Date can not be parsed
return false;
}
} else {
$parsed = $date;
}
if ((strpos($format, 'Y') !== false or strpos($format, 'y') !== false) and !isset($parsed['year'])) {
// Year expected but not found
return false;
}
if (strpos($format, 'M') !== false and !isset($parsed['month'])) {
// Month expected but not found
return false;
}
if (strpos($format, 'd') !== false and !isset($parsed['day'])) {
// Day expected but not found
return false;
}
if ((strpos($format, 'H') !== false or strpos($format, 'h') !== false) and !isset($parsed['hour'])) {
// Hour expected but not found
return false;
}
if (strpos($format, 'm') !== false and !isset($parsed['minute'])) {
// Minute expected but not found
return false;
}
if (strpos($format, 's') !== false and !isset($parsed['second'])) {
// Second expected but not found
return false;
}
// Set not given dateparts
if (isset($parsed['hour']) === false) {
$parsed['hour'] = 12;
}
if (isset($parsed['minute']) === false) {
$parsed['minute'] = 0;
}
if (isset($parsed['second']) === false) {
$parsed['second'] = 0;
}
if (isset($parsed['month']) === false) {
$parsed['month'] = 1;
}
if (isset($parsed['day']) === false) {
$parsed['day'] = 1;
}
if (isset($parsed['year']) === false) {
$parsed['year'] = 1970;
}
if (self::isYearLeapYear($parsed['year'])) {
$parsed['year'] = 1972;
} else {
$parsed['year'] = 1971;
}
$date = new self($parsed, null, $locale);
$timestamp = $date->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $parsed['month'], $parsed['day'], $parsed['year']);
if ($parsed['year'] != $date->date('Y', $timestamp)) {
// Given year differs from parsed year
return false;
}
if ($parsed['month'] != $date->date('n', $timestamp)) {
// Given month differs from parsed month
return false;
}
if ($parsed['day'] != $date->date('j', $timestamp)) {
// Given day differs from parsed day
//.........这里部分代码省略.........
示例2: _startElement
/**
* Internal method, called by xml element handler at start
*
* @param resource $file File handler
* @param string $name Elements name
* @param array $attrib Attributes for this element
*/
protected function _startElement($file, $name, $attrib)
{
if ($this->_seg !== null) {
$this->_content .= "<" . $name;
foreach ($attrib as $key => $value) {
$this->_content .= " {$key}=\"{$value}\"";
}
$this->_content .= ">";
} else {
switch (strtolower($name)) {
case 'header':
if (empty($this->_useId) && isset($attrib['srclang'])) {
if (Locale\Locale::isLocale($attrib['srclang'])) {
$this->_srclang = Locale\Locale::findLocale($attrib['srclang']);
} else {
if (!$this->_options['disableNotices']) {
if ($this->_options['log']) {
$this->_options['log']->notice("The language '{$attrib['srclang']}' can not be set because it does not exist.");
} else {
trigger_error("The language '{$attrib['srclang']}' can not be set because it does not exist.", E_USER_NOTICE);
}
}
$this->_srclang = $attrib['srclang'];
}
}
break;
case 'tu':
if (isset($attrib['tuid'])) {
$this->_tu = $attrib['tuid'];
}
break;
case 'tuv':
if (isset($attrib['xml:lang'])) {
if (Locale\Locale::isLocale($attrib['xml:lang'])) {
$this->_tuv = Locale\Locale::findLocale($attrib['xml:lang']);
} else {
if (!$this->_options['disableNotices']) {
if ($this->_options['log']) {
$this->_options['log']->notice("The language '{$attrib['xml:lang']}' can not be set because it does not exist.");
} else {
trigger_error("The language '{$attrib['xml:lang']}' can not be set because it does not exist.", E_USER_NOTICE);
}
}
$this->_tuv = $attrib['xml:lang'];
}
if (!isset($this->_data[$this->_tuv])) {
$this->_data[$this->_tuv] = array();
}
}
break;
case 'seg':
$this->_seg = true;
$this->_content = null;
break;
default:
break;
}
}
}
示例3: testTerritoryToGetLocale
/**
* @ZF-9488
*/
public function testTerritoryToGetLocale()
{
$value = Locale::findLocale('US');
$this->assertEquals('en_US', $value);
$value = new Locale('US');
$this->assertEquals('en_US', $value->toString());
$value = new Locale('TR');
$this->assertEquals('tr_TR', $value->toString());
}
示例4: _addTranslationData
/**
* Internal function for adding translation data
*
* This may be a new language or additional data for an existing language
* If the options 'clear' is true, then the translation data for the specified
* language is replaced and added otherwise
*
* @see Zend_Locale
* @param array|Zend_Config $content Translation data to add
* @throws Zend_Translate_Exception
* @return Zend_Translate_Adapter Provides fluent interface
*/
private function _addTranslationData($options = array())
{
if ($options instanceof \Zend\Config\Config) {
$options = $options->toArray();
} else {
if (func_num_args() > 1) {
$args = func_get_args();
$options['content'] = array_shift($args);
if (!empty($args)) {
$options['locale'] = array_shift($args);
}
if (!empty($args)) {
$options += array_shift($args);
}
}
}
if ($options['content'] instanceof Translator || $options['content'] instanceof Adapter) {
$options['usetranslateadapter'] = true;
if (!empty($options['locale']) && $options['locale'] !== 'auto') {
$options['content'] = $options['content']->getMessages($options['locale']);
} else {
$content = $options['content'];
$locales = $content->getList();
foreach ($locales as $locale) {
$options['locale'] = $locale;
$options['content'] = $content->getMessages($locale);
$this->_addTranslationData($options);
}
return $this;
}
}
try {
$options['locale'] = Locale\Locale::findLocale($options['locale']);
} catch (Locale\Exception $e) {
throw new Exception("The given Language '{$locale}' does not exist", 0, $e);
}
if ($options['clear'] || !isset($this->_translate[$options['locale']])) {
$this->_translate[$options['locale']] = array();
}
$read = true;
if (isset(self::$_cache)) {
$id = 'Zend_Translate_' . md5(serialize($options['content'])) . '_' . $this->toString();
$temp = self::$_cache->load($id);
if ($temp) {
$read = false;
}
}
if ($options['reload']) {
$read = true;
}
if ($read) {
if (!empty($options['usetranslateadapter'])) {
$temp = array($options['locale'] => $options['content']);
} else {
$temp = $this->_loadTranslationData($options['content'], $options['locale'], $options);
}
}
if (empty($temp)) {
$temp = array();
}
$keys = array_keys($temp);
foreach ($keys as $key) {
if (!isset($this->_translate[$key])) {
$this->_translate[$key] = array();
}
if (array_key_exists($key, $temp) && is_array($temp[$key])) {
$this->_translate[$key] = $temp[$key] + $this->_translate[$key];
}
}
if ($this->_automatic === true) {
$find = new Locale\Locale($options['locale']);
$browser = $find->getEnvironment() + $find->getBrowser();
arsort($browser);
foreach ($browser as $language => $quality) {
if (isset($this->_translate[$language])) {
$this->_options['locale'] = $language;
break;
}
}
}
if ($read and isset(self::$_cache)) {
$id = 'Zend_Translate_' . md5(serialize($options['content'])) . '_' . $this->toString();
if (self::$_cacheTags) {
self::$_cache->save($temp, $id, array($this->_options['tag']));
} else {
self::$_cache->save($temp, $id);
}
}
//.........这里部分代码省略.........
示例5: setLocale
/**
* Sets a new locale for data retreivement
* Example: 'de_XX' will be set to 'de' because 'de_XX' does not exist
* 'xx_YY' will be set to 'root' because 'xx' does not exist
*
* @param string|Zend\Locale\Locale $locale (Optional) Locale for parsing input
* @throws Zend\Currency\Exception When the given locale does not exist
* @return Zend\Currency Provides fluent interface
*/
public function setLocale($locale = null)
{
try {
$locale = Locale\Locale::findLocale($locale);
if (strlen($locale) > 4) {
$this->_options['locale'] = $locale;
} else {
throw new Exception\InvalidArgumentException("No region found within the locale '" . (string) $locale . "'");
}
} catch (Locale\Exception $e) {
throw new Exception\InvalidArgumentException($e->getMessage());
}
// Get currency details
$this->_options['currency'] = $this->getShortName(null, $this->_options['locale']);
$this->_options['name'] = $this->getName(null, $this->_options['locale']);
$this->_options['symbol'] = $this->getSymbol(null, $this->_options['locale']);
return $this;
}
示例6: setLocale
/**
* Sets the locale to use
*
* @param string|\Zend\Locale\Locale $locale
*/
public function setLocale($locale = null)
{
$this->_locale = Locale\Locale::findLocale($locale);
return $this;
}
示例7: setLocale
/**
* Sets the locale to use
*
* @param string|\Zend\Locale\Locale $locale
* @throws \Zend\Validator\Exception On unrecognised region
* @throws \Zend\Validator\Exception On not detected format
* @return \Zend\Validator\PostCode Provides fluid interface
*/
public function setLocale($locale = null)
{
$this->_locale = Locale\Locale::findLocale($locale);
$locale = new Locale\Locale($this->_locale);
$region = $locale->getRegion();
if (empty($region)) {
throw new Exception\InvalidArgumentException("Unable to detect a region for the locale '$locale'");
}
$format = Locale\Locale::getTranslation(
$locale->getRegion(),
'postaltoterritory',
$this->_locale
);
if (empty($format)) {
throw new Exception\InvalidArgumentException("Unable to detect a postcode format for the region '{$locale->getRegion()}'");
}
$this->setFormat($format);
return $this;
}
示例8: testLongLocale
/**
* test MultiPartLocales
* expected boolean
*/
public function testLongLocale()
{
$locale = new LocaleTestHelper('de_Latn_DE');
$this->assertEquals('de_DE', $locale->toString());
$this->assertTrue(LocaleTestHelper::isLocale('de_Latn_CAR_DE_sup3_win'));
$locale = new LocaleTestHelper('de_Latn_DE');
$this->assertEquals('de_DE', $locale->toString());
$this->assertEquals('fr_FR', Locale::findLocale('fr-Arab-FR'));
}
示例9: _checkOptions
/**
* Internal function for checking the options array of proper input values
* See {@link setOptions()} for details.
*
* @param array $options Array of options, keyed by option name: format_type = 'iso' | 'php', fix_date = true | false,
* locale = Zend_Locale | locale string, precision = whole number between -1 and 30
* @throws \Zend\Locale\Exception\InvalidArgumentException
* @return Options array if no option was given
*/
private static function _checkOptions(array $options = array())
{
if (count($options) == 0) {
return self::$_options;
}
foreach ($options as $name => $value) {
$name = strtolower($name);
if ($name !== 'locale') {
if (gettype($value) === 'string') {
$value = strtolower($value);
}
}
switch ($name) {
case 'number_format':
if ($value == self::STANDARD) {
$locale = self::$_options['locale'];
if (isset($options['locale'])) {
$locale = $options['locale'];
}
$options['number_format'] = Cldr::getContent($locale, 'decimalnumber');
} else {
if (gettype($value) !== 'string' and $value !== NULL) {
throw new Exception\InvalidArgumentException("Unknown number format type '" . gettype($value) . "'. " . "Format '{$value}' must be a valid number format string.");
}
}
break;
case 'date_format':
if ($value == self::STANDARD) {
$locale = self::$_options['locale'];
if (isset($options['locale'])) {
$locale = $options['locale'];
}
$options['date_format'] = self::getDateFormat($locale);
} else {
if (gettype($value) !== 'string' and $value !== NULL) {
throw new Exception\InvalidArgumentException("Unknown dateformat type '" . gettype($value) . "'. " . "Format '{$value}' must be a valid ISO or PHP date format string.");
} else {
if (isset($options['format_type']) === true and $options['format_type'] == 'php' or isset($options['format_type']) === false and self::$_options['format_type'] == 'php') {
$options['date_format'] = self::convertPhpToIsoFormat($value);
}
}
}
break;
case 'format_type':
if ($value != 'php' && $value != 'iso') {
throw new Exception\InvalidArgumentException("Unknown date format type '{$value}'. Only 'iso' and 'php'" . " are supported.");
}
break;
case 'fix_date':
if ($value !== true && $value !== false) {
throw new Exception\InvalidArgumentException("Enabling correction of dates must be either true or false" . "(fix_date='{$value}').");
}
break;
case 'locale':
$options['locale'] = Locale::findLocale($value);
break;
case 'cache':
if ($value instanceof \Zend\Cache\Core) {
Cldr::setCache($value);
}
break;
case 'disablecache':
Cldr::disableCache($value);
break;
case 'precision':
if ($value === NULL) {
$value = -1;
}
if ($value < -1 || $value > 30) {
throw new Exception\InvalidArgumentException("'{$value}' precision is not a whole number less than 30.");
}
break;
default:
throw new Exception\InvalidArgumentException("Unknown option: '{$name}' = '{$value}'");
break;
}
}
return $options;
}
示例10: _addTranslationData
/**
* Internal function for adding translation data
*
* This may be a new language or additional data for an existing language
* If the options 'clear' is true, then the translation data for the specified
* language is replaced and added otherwise
*
* @see Zend_Locale
* @param array|Traversable $options Translation data to add
* @throws \Zend\Translator\Exception\InvalidArgumentException
* @return \Zend\Translator\Adapter\AbstractAdapter Provides fluent interface
*/
private function _addTranslationData($options = array())
{
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
} else if (func_num_args() > 1) {
$args = func_get_args();
$options['content'] = array_shift($args);
if (!empty($args)) {
$options['locale'] = array_shift($args);
}
if (!empty($args)) {
$options += array_shift($args);
}
}
if (($options['content'] instanceof Translator\Translator) || ($options['content'] instanceof AbstractAdapter)) {
$options['usetranslateadapter'] = true;
$content = $options['content'];
if (empty($options['locale']) || ($options['locale'] == 'auto')) {
$locales = $content->getList();
} else {
$locales = array(1 => $options['locale']);
}
foreach ($locales as $locale) {
$options['locale'] = $locale;
$options['content'] = $content->getMessages($locale);
$this->_addTranslationData($options);
}
return $this;
}
try {
$options['locale'] = Locale\Locale::findLocale($options['locale']);
} catch (Locale\Exception\ExceptionInterface $e) {
throw new Exception\InvalidArgumentException("The given Language '{$options['locale']}' does not exist", 0, $e);
}
if ($options['clear'] || !isset($this->_translate[$options['locale']])) {
$this->_translate[$options['locale']] = array();
}
$read = true;
if (isset(self::$_cache)) {
$id = 'Zend_Translator_' . md5(serialize($options['content'])) . '_' . $this->toString();
$temp = self::$_cache->getItem($id);
if ($temp) {
$read = false;
}
}
if ($options['reload']) {
$read = true;
}
if ($read) {
if (!empty($options['usetranslateadapter'])) {
$temp = array($options['locale'] => $options['content']);
} else {
$temp = $this->_loadTranslationData($options['content'], $options['locale'], $options);
}
}
if (empty($temp)) {
$temp = array();
}
$keys = array_keys($temp);
foreach($keys as $key) {
if (!isset($this->_translate[$key])) {
$this->_translate[$key] = array();
}
if (array_key_exists($key, $temp) && is_array($temp[$key])) {
$this->_translate[$key] = $temp[$key] + $this->_translate[$key];
}
}
if ($this->_automatic === true) {
$find = new Locale\Locale($options['locale']);
$browser = $find->getEnvironment() + $find->getBrowser();
arsort($browser);
foreach($browser as $language => $quality) {
if (isset($this->_translate[$language])) {
$this->_options['locale'] = $language;
//.........这里部分代码省略.........
示例11: setLocale
/**
* Sets the locale option
*
* @param string|Locale $locale
* @return Iban provides a fluent interface
*/
public function setLocale($locale = null)
{
if ($locale !== false) {
$locale = Locale::findLocale($locale);
if (strlen($locale) < 4) {
throw new Exception\InvalidArgumentException('Region must be given for IBAN validation');
}
}
$this->locale = $locale;
return $this;
}
示例12: _addTranslationData
/**
* Internal function for adding translation data
*
* It may be a new language or additional data for existing language
* If $clear parameter is true, then translation data for specified
* language is replaced and added otherwise
*
* @see Zend_Locale
* @param array|string $data Translation data
* @param string|\Zend\Locale\Locale $locale Locale/Language to add data for, identical with locale identifier,
* @see Zend_Locale for more information
* @param array $options (optional) Option for this Adapter
* @throws \Zend\Translator\Exception
* @return \Zend\Translator\Adapter\Adapter Provides fluent interface
*/
private function _addTranslationData($data, $locale, array $options = array())
{
if ($data instanceof Translator\Translator || $data instanceof Adapter) {
$options['usetranslateadapter'] = true;
if (!empty($locale)) {
$data = $data->getMessages($locale);
} else {
$locales = $data->getList();
foreach ($locales as $locale) {
$trans = $data->getMessages($locale);
$this->_addTranslationData($trans, $locale, $options);
}
return $this;
}
}
try {
$locale = Locale\Locale::findLocale($locale);
} catch (Locale\Exception $e) {
throw new Translator\Exception("The given Language '{$locale}' does not exist", 0, $e);
}
if ($options['clear'] || !isset($this->_translate[$locale])) {
$this->_translate[$locale] = array();
}
$read = true;
if (isset(self::$_cache)) {
$id = 'Zend_Translate_' . md5(serialize($data)) . '_' . $this->toString();
$temp = self::$_cache->load($id);
if ($temp) {
$read = false;
}
}
if ($options['reload']) {
$read = true;
}
if ($read) {
if (!empty($options['usetranslateadapter'])) {
$temp = array($locale => $data);
} else {
$temp = $this->_loadTranslationData($data, $locale, $options);
}
}
if (empty($temp)) {
$temp = array();
}
$keys = array_keys($temp);
foreach ($keys as $key) {
if (!isset($this->_translate[$key])) {
$this->_translate[$key] = array();
}
if (array_key_exists($key, $temp) && is_array($temp[$key])) {
$this->_translate[$key] = $temp[$key] + $this->_translate[$key];
}
}
if ($this->_automatic === true) {
$find = new Locale\Locale($locale);
$browser = $find->getEnvironment() + $find->getBrowser();
arsort($browser);
foreach ($browser as $language => $quality) {
if (isset($this->_translate[$language])) {
$this->_options['locale'] = $language;
break;
}
}
}
if ($read and isset(self::$_cache)) {
$id = 'Zend_Translate_' . md5(serialize($data)) . '_' . $this->toString();
self::$_cache->save($temp, $id, array('Zend_Translate'));
}
return $this;
}