本文整理汇总了PHP中Zend\Locale\Locale类的典型用法代码示例。如果您正苦于以下问题:PHP Locale类的具体用法?PHP Locale怎么用?PHP Locale使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Locale类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* Setup environment
*/
public function setUp()
{
date_default_timezone_set("America/Chicago");
\Zend\Locale\Locale::setDefault('en');
Parser\TypeLoader::resetMap();
$this->_request = new \Zend\AMF\Request\StreamRequest();
}
示例2: setUp
/**
* Setup environment
*/
public function setUp()
{
date_default_timezone_set('America/Chicago');
Locale::setDefault('en_US');
Parser\TypeLoader::resetMap();
$this->_response = new \Zend\AMF\Response\StreamResponse();
}
示例3: direct
/**
* Translate a message
* You can give multiple params or an array of params.
* If you want to output another locale just set it as last single parameter
* Example 1: translate('%1\$s + %2\$s', $value1, $value2, $locale);
* Example 2: translate('%1\$s + %2\$s', array($value1, $value2), $locale);
*
* @param string $messageid Id of the message to be translated
* @return string|\Zend\View\Helper\Translate Translated message
*/
public function direct($messageid = null)
{
if ($messageid === null) {
return $this;
}
$translate = $this->getTranslator();
$options = func_get_args();
array_shift($options);
$count = count($options);
$locale = null;
if ($count > 0) {
if (\Zend\Locale\Locale::isLocale($options[$count - 1]) !== false) {
$locale = array_pop($options);
}
}
if (count($options) === 1 and is_array($options[0]) === true) {
$options = $options[0];
}
if ($translate !== null) {
$messageid = $translate->translate($messageid, $locale);
}
if (count($options) === 0) {
return $messageid;
}
return vsprintf($messageid, $options);
}
示例4: testIsLocale
/**
* Tests if the given language is really a language
*/
public function testIsLocale()
{
foreach ($this->_languages as $lang) {
if (!Locale::isLocale($lang, true)) {
$this->fail("Language directory '{$lang}' not a valid locale");
}
}
}
示例5: setUp
/**
* Setup environment
*/
public function setUp()
{
$this->_originaltimezone = date_default_timezone_get();
date_default_timezone_set('America/Chicago');
Locale::setFallback('en_US');
Parser\TypeLoader::resetMap();
$this->_response = new \Zend\Amf\Response\StreamResponse();
}
示例6: setUp
/**
* Setup environment
*/
public function setUp()
{
$this->_originaltimezone = date_default_timezone_get();
date_default_timezone_set("America/Chicago");
\Zend\Locale\Locale::setFallback('en');
Parser\TypeLoader::resetMap();
$this->_request = new \Zend\Amf\Request\StreamRequest();
}
示例7: getLocale
/**
* Retrieve locale object
*
* @return \Zend\Locale\Locale
*/
public function getLocale()
{
if (null === $this->_locale) {
$options = $this->getOptions();
if (!isset($options['default'])) {
$this->_locale = new SystemLocale\Locale();
} elseif (!isset($options['force']) || (bool) $options['force'] == false) {
// Don't force any locale, just go for auto detection
SystemLocale\Locale::setDefault($options['default']);
$this->_locale = new SystemLocale\Locale();
} else {
$this->_locale = new SystemLocale\Locale($options['default']);
}
$key = isset($options['registry_key']) && !is_numeric($options['registry_key']) ? $options['registry_key'] : self::DEFAULT_REGISTRY_KEY;
\Zend\Registry::set($key, $this->_locale);
}
return $this->_locale;
}
示例8: direct
/**
* Output a formatted currency
*
* @param integer|float $value Currency value to output
* @param string|Zend_Locale|\Zend\Currency\Currency $currency OPTIONAL Currency to use for this call
* @return string Formatted currency
*/
public function direct($value = null, $currency = null)
{
if ($value === null) {
return $this;
}
if (is_string($currency) || $currency instanceof Locale\Locale) {
if (Locale\Locale::isLocale($currency)) {
$currency = array('locale' => $currency);
}
}
if (is_string($currency)) {
$currency = array('currency' => $currency);
}
if (is_array($currency)) {
return $this->_currency->toCurrency($value, $currency);
}
return $this->_currency->toCurrency($value);
}
示例9: __invoke
/**
* Translate a message
* You can give multiple params or an array of params.
* If you want to output another locale just set it as last single parameter
* Example 1: translate('%1\$s + %2\$s', $value1, $value2, $locale);
* Example 2: translate('%1\$s + %2\$s', array($value1, $value2), $locale);
*
* @param string $messageid Id of the message to be translated
* @return string|\Zend\View\Helper\Translator Translated message
*/
public function __invoke($messageid = null)
{
if ($messageid === null) {
return $this;
}
$translator = $this->getTranslator();
$options = func_get_args();
array_shift($options);
$count = count($options);
$locale = null;
if ($count > 0) {
if (Locale::isLocale($options[$count - 1]) !== false) {
// Don't treat last option as the locale if doing so will result in an error
if (is_array($options[0]) || @vsprintf($messageid, array_slice($options, 0, -1)) !== false) {
$locale = array_pop($options);
}
}
}
if (count($options) === 1 and is_array($options[0]) === true) {
$options = $options[0];
}
if ($translator !== null) {
$messageid = $translator->translate($messageid, $locale);
}
if (count($options) === 0) {
return $messageid;
}
return vsprintf($messageid, $options);
}
示例10: dirname
<?php
// Set used namespaces
use Zend\Loader\StandardAutoloader;
use Zend\Locale\Locale;
use Zend\Service\LiveDocx\Helper;
// Turn up error reporting
error_reporting(E_ALL | E_STRICT);
// Library base
$base = dirname(dirname(dirname(dirname(__DIR__))));
// Set up autoloader
require_once "{$base}/library/Zend/Loader/StandardAutoloader.php";
$loader = new StandardAutoloader();
$loader->registerNamespace('Zend', "{$base}/library/Zend");
$loader->register();
// Include utility class
require_once "{$base}/demos/Zend/Service/LiveDocx/library/Zend/Service/LiveDocx/Helper.php";
// Set fallback locale
Locale::setFallback(Helper::LOCALE);
// Ensure LiveDocx credentials are available
if (false === Helper::credentialsAvailable()) {
Helper::printLine(Helper::credentialsHowTo());
exit;
}
unset($base);
示例11: _checkOptions
/**
* Internal method for checking the options array
*
* @param array $options Options to check
* @throws Zend\Currency\Exception On unknown position
* @throws Zend\Currency\Exception On unknown locale
* @throws Zend\Currency\Exception On unknown display
* @throws Zend\Currency\Exception On precision not between -1 and 30
* @throws Zend\Currency\Exception On problem with script conversion
* @throws Zend\Currency\Exception On unknown options
* @return array
*/
protected function _checkOptions(array $options = array())
{
if (count($options) === 0) {
return $this->_options;
}
foreach ($options as $name => $value) {
$name = strtolower($name);
if ($name !== 'format') {
if (gettype($value) === 'string') {
$value = strtolower($value);
}
}
switch ($name) {
case 'position':
if ($value !== self::STANDARD and $value !== self::RIGHT and $value !== self::LEFT) {
throw new Exception\InvalidArgumentException("Unknown position '" . $value . "'");
}
break;
case 'format':
if (empty($value) === false and Locale\Locale::isLocale($value) === false) {
if (!is_string($value) || strpos($value, '0') === false) {
throw new Exception\InvalidArgumentException('\'' . (gettype($value) === 'object' ? get_class($value) : $value) . '\' is no format token');
}
}
break;
case 'display':
if (is_numeric($value) and $value !== self::NO_SYMBOL and $value !== self::USE_SYMBOL and $value !== self::USE_SHORTNAME and $value !== self::USE_NAME) {
throw new Exception\InvalidArgumentException("Unknown display '{$value}'");
}
break;
case 'precision':
if ($value === null) {
$value = -1;
}
if ($value < -1 or $value > 30) {
throw new Exception\InvalidArgumentException("'{$value}' precision has to be between -1 and 30.");
}
break;
case 'script':
try {
Locale\Format::convertNumerals(0, $options['script']);
} catch (Locale\Exception $e) {
throw new Exception\InvalidArgumentException($e->getMessage());
}
break;
default:
break;
}
}
return $options;
}
示例12: isTranslated
/**
* Checks if a string is translated within the source or not
* returns boolean
*
* @param string $messageId Translation string
* @param boolean $original (optional) Allow translation only for original language
* when true, a translation for 'en_US' would give false when it can
* be translated with 'en' only
* @param string|\Zend\Locale\Locale $locale (optional) Locale/Language to use, identical with locale identifier,
* see Zend_Locale for more information
* @return boolean
*/
public function isTranslated($messageId, $original = false, $locale = null)
{
if ($original !== false and $original !== true) {
$locale = $original;
$original = false;
}
if ($locale === null) {
$locale = $this->_options['locale'];
}
if (!Locale\Locale::isLocale($locale, true, false)) {
if (!Locale\Locale::isLocale($locale, false, false)) {
// language does not exist, return original string
return false;
}
$locale = new Locale\Locale($locale);
}
$locale = (string) $locale;
if ((is_string($messageId) || is_int($messageId)) && isset($this->_translate[$locale][$messageId])) {
// return original translation
return true;
} else {
if (strlen($locale) != 2 and $original === false) {
// faster than creating a new locale and separate the leading part
$locale = substr($locale, 0, -strlen(strrchr($locale, '_')));
if ((is_string($messageId) || is_int($messageId)) && isset($this->_translate[$locale][$messageId])) {
// return regionless translation (en_US -> en)
return true;
}
}
}
// No translation found, return original
return false;
}
示例13: testSetOption
/**
* test setOption
* expected boolean
*/
public function testSetOption()
{
$this->assertEquals(8, count(Format::setOptions(array('format_type' => 'php'))));
$this->assertTrue(is_array(Format::setOptions()));
try {
$this->assertTrue(Format::setOptions(array('format_type' => 'xxx')));
$this->fail("exception expected");
} catch (InvalidArgumentException $e) {
// success
}
try {
$this->assertTrue(Format::setOptions(array('myformat' => 'xxx')));
$this->fail("exception expected");
} catch (InvalidArgumentException $e) {
// success
}
$format = Format::setOptions(array('locale' => 'de', 'number_format' => Format::STANDARD));
$test = Cldr::getContent('de', 'decimalnumber');
$this->assertEquals($test, $format['number_format']);
try {
$this->assertFalse(Format::setOptions(array('number_format' => array('x' => 'x'))));
$this->fail("exception expected");
} catch (InvalidArgumentException $e) {
// success
}
$format = Format::setOptions(array('locale' => 'de', 'date_format' => Format::STANDARD));
$test = Format::getDateFormat('de');
$this->assertEquals($test, $format['date_format']);
try {
$this->assertFalse(Format::setOptions(array('date_format' => array('x' => 'x'))));
$this->fail("exception expected");
} catch (InvalidArgumentException $e) {
// success
}
try {
$this->assertFalse(is_array(Format::setOptions(array('fix_date' => 'no'))));
$this->fail("exception expected");
} catch (InvalidArgumentException $e) {
// success
}
$format = Format::setOptions(array('locale' => Format::STANDARD));
$locale = new Locale();
$this->assertEquals($locale->toString(), $format['locale']);
try {
$this->assertFalse(is_array(Format::setOptions(array('locale' => 'nolocale'))));
$this->fail("exception expected");
} catch (InvalidArgumentException $e) {
// success
}
try {
$this->assertFalse(is_array(Format::setOptions(array('precision' => 50))));
$this->fail("exception expected");
} catch (InvalidArgumentException $e) {
// success
}
// test interaction between class-wide default date format and using locale's default format
try {
$result = array('date_format' => 'MMM d, y', 'locale' => 'en_US', 'month' => '7', 'day' => '4', 'year' => '2007');
Format::setOptions(array('format_type' => 'iso', 'date_format' => 'MMM d, y', 'locale' => 'en_US'));
// test setUp
} catch (InvalidArgumentException $e) {
$this->fail("exception expected");
}
try {
// uses global date_format with global locale
$this->assertSame($result, Format::getDate('July 4, 2007'));
} catch (InvalidArgumentException $e) {
$this->fail("exception expected");
}
try {
// uses global date_format with given locale
$this->assertSame($result, Format::getDate('July 4, 2007', array('locale' => 'en_US')));
} catch (InvalidArgumentException $e) {
$this->fail("exception expected");
}
try {
// sets a new global date format
Format::setOptions(array('date_format' => 'M-d-y'));
} catch (InvalidArgumentException $e) {
$this->fail("exception expected");
}
try {
// uses global date format with given locale
// but this date format differs from the original set... (MMMM d, yyyy != M-d-y)
$expected = Format::getDate('July 4, 2007', array('locale' => 'en_US'));
$this->assertSame($expected['year'], $result['year']);
$this->assertSame($expected['month'], $result['month']);
$this->assertSame($expected['day'], $result['day']);
} catch (InvalidArgumentException $e) {
$this->fail("exception expected");
}
try {
// the following should not be used... instead of null, Locale::ZFDEFAULT should be used
// uses given local with standard format from this locale
$this->assertSame($result, Format::getDate('July 4, 2007', array('locale' => 'en_US', 'date_format' => null)));
} catch (InvalidArgumentException $e) {
//.........这里部分代码省略.........
示例14: _getLocalizedQuestion
/**
* Determine the value of a localized string, and compare it to a given value
*
* @param string $value
* @param boolean $yes
* @param array $locale
* @return boolean
*/
protected function _getLocalizedQuestion($value, $yes, $locale)
{
if ($yes == true) {
$question = 'yes';
$return = true;
} else {
$question = 'no';
$return = false;
}
$str = Locale::getTranslation($question, 'question', $locale);
$str = explode(':', $str);
if (!empty($str)) {
foreach ($str as $no) {
if ($no == $value || strtolower($no) == strtolower($value)) {
return $return;
}
}
}
}
示例15: findLocale
/**
* Finds the proper locale based on the input
* Checks if it exists, degrades it when necessary
* Detects registry locale and when all fails tries to detect a automatic locale
* Returns the found locale as string
*
* @param string $locale
* @throws \Zend\Locale\Exception When the given locale is no locale or the autodetection fails
* @return string
*/
public static function findLocale($locale = null)
{
if ($locale === null) {
if (Registry::isRegistered('Zend_Locale')) {
$locale = Registry::get('Zend_Locale');
}
}
if ($locale === null) {
$locale = new Locale();
}
if (!Locale::isLocale($locale, true, false)) {
if (!Locale::isLocale($locale, false, false)) {
throw new Exception("The locale '{$locale}' is no known locale");
}
$locale = new Locale($locale);
}
$locale = self::_prepareLocale($locale);
return $locale;
}