本文整理汇总了PHP中Zend\Locale\Locale::getEnvironment方法的典型用法代码示例。如果您正苦于以下问题:PHP Locale::getEnvironment方法的具体用法?PHP Locale::getEnvironment怎么用?PHP Locale::getEnvironment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Locale\Locale
的用法示例。
在下文中一共展示了Locale::getEnvironment方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testIsLocale
/**
* test isLocale
* expected boolean
*/
public function testIsLocale()
{
$locale = new LocaleTestHelper('ar');
$this->assertTrue(LocaleTestHelper::isLocale($locale));
$this->assertTrue(LocaleTestHelper::isLocale('de'));
$this->assertTrue(LocaleTestHelper::isLocale('de_AT'));
$this->assertTrue(LocaleTestHelper::isLocale('de_xx'));
$this->assertFalse(LocaleTestHelper::isLocale('yy'));
$this->assertFalse(LocaleTestHelper::isLocale(1234));
$this->assertFalse(LocaleTestHelper::isLocale('', true));
$this->assertFalse(LocaleTestHelper::isLocale('', false));
$this->assertTrue(LocaleTestHelper::isLocale('auto'));
$this->assertTrue(LocaleTestHelper::isLocale('browser'));
if (count(Locale::getEnvironment()) != 0) {
$this->assertTrue(LocaleTestHelper::isLocale('environment'));
}
}
示例2: _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);
}
}
//.........这里部分代码省略.........
示例3: _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;
//.........这里部分代码省略.........
示例4: testIsLocale
/**
* test isLocale
* expected boolean
*/
public function testIsLocale()
{
$locale = new LocaleTestHelper('ar');
$this->assertTrue(LocaleTestHelper::isLocale($locale));
$this->assertTrue(LocaleTestHelper::isLocale('de'));
$this->assertTrue(LocaleTestHelper::isLocale('de_AT'));
$this->assertTrue(LocaleTestHelper::isLocale('de_xx'));
$this->assertFalse(LocaleTestHelper::isLocale('yy'));
$this->assertFalse(LocaleTestHelper::isLocale(1234));
$this->assertFalse(LocaleTestHelper::isLocale('', true));
$this->assertFalse(LocaleTestHelper::isLocale('', false));
$this->assertTrue(LocaleTestHelper::isLocale('auto'));
$this->assertTrue(LocaleTestHelper::isLocale('browser'));
if (count(Locale::getEnvironment()) != 0) {
$this->assertTrue(LocaleTestHelper::isLocale('environment'));
}
set_error_handler(array($this, 'errorHandlerIgnore'));
LocaleTestHelper::$compatibilityMode = true;
$this->assertEquals('ar', LocaleTestHelper::isLocale($locale));
$this->assertEquals('de', LocaleTestHelper::isLocale('de'));
$this->assertEquals('de_AT', LocaleTestHelper::isLocale('de_AT'));
$this->assertEquals('de', LocaleTestHelper::isLocale('de_xx'));
$this->assertFalse(LocaleTestHelper::isLocale('yy'));
$this->assertFalse(LocaleTestHelper::isLocale(1234));
$this->assertFalse(LocaleTestHelper::isLocale('', true));
$this->assertFalse(LocaleTestHelper::isLocale('', false));
$this->assertTrue(is_string(LocaleTestHelper::isLocale('auto')));
$this->assertTrue(is_string(LocaleTestHelper::isLocale('browser')));
if (count(Locale::getEnvironment()) != 0) {
$this->assertTrue(is_string(LocaleTestHelper::isLocale('environment')));
}
restore_error_handler();
}
示例5: _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;
}