php Zend-Locale-Locale类(方法)实例源码

下面列出了php Zend-Locale-Locale 类(方法)源码代码实例,从而了解它的用法。

作者:stunt    项目:zf   
/**
  * 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();
 }

作者:stunt    项目:zf   
/**
  * 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();
 }

作者:navti    项目:xerxes-pazpar   
/**
  * 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);
 }

作者:rufli    项目:zf   
/**
  * 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");
         }
     }
 }

作者:navassouz    项目:zf   
/**
  * 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();
 }

作者:navassouz    项目:zf   
/**
  * 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();
 }

作者:heiglandrea    项目:zf   
/**
  * 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;
 }

作者:rexma    项目:zf   
/**
  * 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);
 }

作者:nevvermin    项目:zf   
/**
  * 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);
 }

作者:alab100110    项目:zf   
<?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);

作者:nevvermin    项目:zf   
/**
  * 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;
 }

作者:heiglandrea    项目:zf   
/**
  * 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;
 }

作者:alab100110    项目:zf   
/**
  * 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) {
//.........这里部分代码省略.........

作者:alab100110    项目:zf   
/**
  * 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;
             }
         }
     }
 }

作者:stunt    项目:zf   
/**
  * 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;
 }

作者:rafalwrzeszc    项目:zf   
/**
  * 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;
 }

作者:rexma    项目:zf   
/**
  * Internal function for checking the locale
  *
  * @param string|\Zend\Locale $locale Locale to check
  * @return string
  */
 private static function _checkLocale($locale)
 {
     if (empty($locale)) {
         $locale = new Locale();
     }
     if (!Locale::isLocale((string) $locale)) {
         throw new Exception\InvalidArgumentException("Locale (" . (string) $locale . ") is a unknown locale");
     }
     return (string) $locale;
 }

作者:nresn    项目:AriadneSandbo   
/**
  * Sets the locale to use
  *
  * @param string|\Zend\Locale\Locale $locale
  */
 public function setLocale($locale = null)
 {
     $this->_locale = Locale\Locale::findLocale($locale);
     return $this;
 }

作者:bradley-hol    项目:zf   
/**
  * Returns detailed informations from the variant table
  * If no detail is given a complete table is returned
  *
  * @param string  $locale Normalized locale
  * @param boolean $invert Invert output of the data
  * @param string|array $detail Detail to return information for
  * @return array
  */
 public static function getDisplayVariant($locale, $invert = false, $detail = null)
 {
     if ($detail !== null) {
         return Locale::getDisplayVariant($locale);
     } else {
         $list = ZFLocale::getLocaleList();
         foreach ($list as $key => $value) {
             $list[$key] = Locale::getDisplayVariant($key);
         }
         if ($invert) {
             array_flip($list);
         }
         return $list;
     }
 }

作者:niallmccrudde    项目:zf   
/**
     * 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;
    }


问题


面经


文章

微信
公众号

扫码关注公众号