/** * Sets the locale. * * @param Zend_Locale|string|null * @return Jrm_Filter_Boolean */ public function setLocale($locale) { $this->_localeValues = array(); if (!is_null($locale)) { if (!class_exists('Zend_Locale')) { require_once 'Zend/Locale.php'; } if (!$locale instanceof Zend_Locale) { $locale = new Zend_Locale($locale); } $q = $locale->getQuestion(); $this->_localeValues = array($q['yes'] => true, $q['yesabbr'] => true, $q['no'] => false, $q['noabbr'] => false); } return $this; }
/** * test getQuestion * expected true */ public function testgetQuestion() { $value = new Zend_Locale(); $list = $value->getQuestion(); $this->assertTrue(isset($list['yes'])); $list = $value->getQuestion('de'); $this->assertEquals('ja', $list['yes']); $this->assertTrue(is_array($value->getQuestion('auto'))); $this->assertTrue(is_array($value->getQuestion('browser'))); $this->assertTrue(is_array($value->getQuestion('environment'))); }
/** * test getQuestion * expected true */ public function testgetQuestion() { $value = new Zend_Locale(); $list = $value->getQuestion(); $this->assertTrue(isset($list['yes']), 'Question not returned'); $list = $value->getQuestion('de'); $this->assertTrue(isset($list['yes']), 'Question not returned'); }
/** * Reads a normalized value, localizes and returns it. * Returns an empty string if no value is passed. * @param mixed $value * @param string $type (boolean|date|time|integer|float|decimal|filesize) * @param integer $num_of_decimals used only if type is float or decimal * @return mixed */ private function _format($value, $type, $num_of_decimals) { if (strlen($value) == 0) { return ''; } switch ($type) { case 'boolean': $value = $value == 1 ? 'yes' : 'no'; $yes_no = Zend_Locale::getQuestion($this->_locale_engine); return $yes_no[$value]; case 'date': $date = new Zend_Date($value, "yyyy-MM-dd", $this->_locale_engine); return $date->get(Zend_Date::DATES, $this->_locale_engine); case 'time': $date = new Zend_Date($value, "HH:mm:ss", $this->_locale_engine); return $date->get(Zend_Date::TIME_SHORT, $this->_locale_engine); case 'datetime': $date = new Zend_Date($value, "yyyy-MM-dd HH:mm:ss", $this->_locale_engine); return $date->get(Zend_Date::DATES, $this->_locale_engine) . ' ' . $date->get(Zend_Date::TIME_MEDIUM, $this->_locale_engine); case 'integer': return Zend_Locale_Format::toNumber($value, array('precision' => 0, 'locale' => $this->_locale_engine)); case 'float': if ($num_of_decimals === null) { $num_of_decimals = 3; } return Zend_Locale_Format::toNumber($value, array('precision' => $num_of_decimals, 'locale' => $this->_locale_engine)); case 'decimal': if ($num_of_decimals === null) { $num_of_decimals = 2; } return Zend_Locale_Format::toNumber($value, array('precision' => $num_of_decimals, 'locale' => $this->_locale_engine)); case 'filesize': if ($num_of_decimals === null) { $num_of_decimals = 2; } $units = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'); for ($i = 0; $value > 1024 and $i < count($units) - 1; $i++) { $value /= 1024; } return Zend_Locale_Format::toNumber($value, array('precision' => $num_of_decimals, 'locale' => $this->_locale_engine)) . " {$units[$i]}"; } return $value; }