/** * 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; }
/** * 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; } } } }