public function init() { // Send default settings according to locale $locale = i18n::get_locale(); $symbols = Zend_Locale_Data::getList($locale, 'symbols'); $currency = Currency::config()->currency_symbol; $decimals = $symbols['decimal']; $thousands = $decimals == ',' ? ' ' : ','; // Accouting needs to be initialized globally FormExtraJquery::include_accounting(); Requirements::customScript(<<<EOT window.accounting.settings = { currency: { symbol : "{$currency}", format: "%s%v", decimal : "{$decimals}", thousand: "{$thousands}", precision : 2 }, number: { precision : 0, thousand: "{$thousands}", decimal : "{$decimals}" } } EOT , 'accountingInit'); }
protected function _toHtml() { $localeCode = Mage::app()->getLocale()->getLocaleCode(); // get days names $days = Zend_Locale_Data::getList($localeCode, 'days'); $this->assign('days', array('wide' => Zend_Json::encode(array_values($days['format']['wide'])), 'abbreviated' => Zend_Json::encode(array_values($days['format']['abbreviated'])))); // get months names $months = Zend_Locale_Data::getList($localeCode, 'months'); $this->assign('months', array('wide' => Zend_Json::encode(array_values($months['format']['wide'])), 'abbreviated' => Zend_Json::encode(array_values($months['format']['abbreviated'])))); // get "today" and "week" words $this->assign('today', Zend_Json::encode(Zend_Locale_Data::getContent($localeCode, 'relative', 0))); $this->assign('week', Zend_Json::encode(Zend_Locale_Data::getContent($localeCode, 'field', 'week'))); // get "am" & "pm" words $this->assign('am', Zend_Json::encode(Zend_Locale_Data::getContent($localeCode, 'am'))); $this->assign('pm', Zend_Json::encode(Zend_Locale_Data::getContent($localeCode, 'pm'))); // get first day of week and weekend days $this->assign('firstDay', (int) Mage::getStoreConfig('general/locale/firstday')); $this->assign('weekendDays', Zend_Json::encode((string) Mage::getStoreConfig('general/locale/weekend'))); // define default format and tooltip format $this->assign('defaultFormat', Zend_Json::encode(Mage::app()->getLocale()->getDateStrFormat(Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM))); $this->assign('toolTipFormat', Zend_Json::encode(Mage::app()->getLocale()->getDateStrFormat(Mage_Core_Model_Locale::FORMAT_TYPE_LONG))); // get days and months for en_US locale - calendar will parse exactly in this locale $days = Zend_Locale_Data::getList('en_US', 'days'); $months = Zend_Locale_Data::getList('en_US', 'months'); $enUS = new stdClass(); $enUS->m = new stdClass(); $enUS->m->wide = array_values($months['format']['wide']); $enUS->m->abbr = array_values($months['format']['abbreviated']); $this->assign('enUS', Zend_Json::encode($enUS)); return parent::_toHtml(); }
public static function initVariables() { $locale = i18n::get_locale(); $symbols = Zend_Locale_Data::getList($locale, 'symbols'); self::$_decimals = $symbols['decimal']; self::$_thousands = self::$_decimals == ',' ? ' ' : ','; }
public function init() { $this->setTitle('Language Pack')->setDescription('Upload a modified language pack. This will overwrite any language entries already in a language file.')->setAction(Zend_Controller_Front::getInstance()->getRouter()->assemble(array())); $languageList = Zend_Locale_Data::getList('en', 'language'); $territoryList = Zend_Locale_Data::getList('en', 'territory'); $languageNameList = array(); foreach (array_keys(Zend_Locale::getLocaleList()) as $localeCode) { $localeArray = explode('_', $localeCode); $locale = array_shift($localeArray); $territory = array_shift($localeArray); if (isset($languageList[$locale]) && !empty($languageList[$locale])) { $languageNameList[$localeCode] = $languageList[$locale]; if (isset($territoryList[$territory]) && !empty($territoryList[$territory])) { $languageNameList[$localeCode] .= " ({$territoryList[$territory]})"; } $languageNameList[$localeCode] .= " [{$localeCode}]"; } } asort($languageNameList); $this->addElement('Select', 'locale', array('label' => 'Language', 'description' => 'Which language will this language pack be applied to?', 'multiOptions' => $languageNameList)); $this->addElement('File', 'file', array('label' => 'Language File', 'description' => 'Upload a language CSV file.', 'required' => true)); // Init submit $this->addElement('Button', 'submit', array('label' => 'Upload', 'type' => 'submit', 'decorators' => array('ViewHelper'))); $this->addElement('Cancel', 'cancel', array('prependText' => ' or ', 'link' => true, 'label' => 'cancel', 'onclick' => 'history.go(-1); return false;', 'decorators' => array('ViewHelper'))); }
public function indexAction() { $this->view->navigation = $navigation = Engine_Api::_()->getApi('menus', 'core')->getNavigation('core_footer'); // Languages $translate = Zend_Registry::get('Zend_Translate'); $languageList = $translate->getList(); //$currentLocale = Zend_Registry::get('Locale')->__toString(); // Prepare default langauge $defaultLanguage = Engine_Api::_()->getApi('settings', 'core')->getSetting('core.locale.locale', 'en'); if (!in_array($defaultLanguage, $languageList)) { if ($defaultLanguage == 'auto' && isset($languageList['en'])) { $defaultLanguage = 'en'; } else { $defaultLanguage = null; } } // Prepare language name list $languageNameList = array(); $languageDataList = Zend_Locale_Data::getList(null, 'language'); $territoryDataList = Zend_Locale_Data::getList(null, 'territory'); foreach ($languageList as $localeCode) { $languageNameList[$localeCode] = Zend_Locale::getTranslation($localeCode, 'language', $localeCode); if (empty($languageNameList[$localeCode])) { list($locale, $territory) = explode('_', $localeCode); $languageNameList[$localeCode] = "{$territoryDataList[$territory]} {$languageDataList[$locale]}"; } } $languageNameList = array_merge(array($defaultLanguage => $defaultLanguage), $languageNameList); $this->view->languageNameList = $languageNameList; }
/** * Functions returns array with price formating info for js function * formatCurrency in js/varien/js.js * * @return array */ public function getJsPriceFormat() { $format = Zend_Locale_Data::getContent($this->getLocaleCode(), 'currencynumber'); $symbols = Zend_Locale_Data::getList($this->getLocaleCode(), 'symbols'); $pos = strpos($format, ';'); if ($pos !== false) { $format = substr($format, 0, $pos); } $format = preg_replace("/[^0\\#\\.,]/", "", $format); $totalPrecision = 0; $decimalPoint = strpos($format, '.'); if ($decimalPoint !== false) { $totalPrecision = strlen($format) - (strrpos($format, '.') + 1); } else { $decimalPoint = strlen($format); } //hook for changing precision $totalPrecision = VF_Currency_Model_Directory_Currency::PRECISION; $requiredPrecision = $totalPrecision; $temp = substr($format, $decimalPoint); $pos = strpos($temp, '#'); if ($pos !== false) { $requiredPrecision = strlen($temp) - $pos - $totalPrecision; } $group = 0; if (strrpos($format, ',') !== false) { $group = $decimalPoint - strrpos($format, ',') - 1; } else { $group = strrpos($format, '.'); } $integerRequired = strpos($format, '.') - strpos($format, '0'); $result = array('pattern' => Mage::app()->getStore()->getCurrentCurrency()->getOutputFormat(), 'precision' => $totalPrecision, 'requiredPrecision' => $requiredPrecision, 'decimalSymbol' => $symbols['decimal'], 'groupSymbol' => $symbols['group'], 'groupLength' => $group, 'integerRequired' => $integerRequired); return $result; }
public function indexAction() { if (Engine_Api::_()->user()->getViewer()->getIdentity()) { return $this->_helper->redirector->gotoRoute(array('action' => 'home'), 'user_general', true); } /* if (isset($_SESSION['skip_registration'])) { return $this -> _helper -> redirector -> gotoRoute(array(), 'user_home', true); } */ // Languages $translate = Zend_Registry::get('Zend_Translate'); $languageList = $translate->getList(); // Prepare default langauge $defaultLanguage = Engine_Api::_()->getApi('settings', 'core')->getSetting('core.locale.locale', 'en'); if (!in_array($defaultLanguage, $languageList)) { if ($defaultLanguage == 'auto' && isset($languageList['en'])) { $defaultLanguage = 'en'; } else { $defaultLanguage = null; } } // Prepare language name list $languageNameList = array(); $languageDataList = Zend_Locale_Data::getList(null, 'language'); $territoryDataList = Zend_Locale_Data::getList(null, 'territory'); foreach ($languageList as $localeCode) { $languageNameList[$localeCode] = Engine_String::ucfirst(Zend_Locale::getTranslation($localeCode, 'language', $localeCode)); if (empty($languageNameList[$localeCode])) { if (false !== strpos($localeCode, '_')) { list($locale, $territory) = explode('_', $localeCode); } else { $locale = $localeCode; $territory = null; } if (isset($territoryDataList[$territory]) && isset($languageDataList[$locale])) { $languageNameList[$localeCode] = $territoryDataList[$territory] . ' ' . $languageDataList[$locale]; } else { if (isset($territoryDataList[$territory])) { $languageNameList[$localeCode] = $territoryDataList[$territory]; } else { if (isset($languageDataList[$locale])) { $languageNameList[$localeCode] = $languageDataList[$locale]; } else { continue; } } } } } $languageNameList = array_merge(array($defaultLanguage => $defaultLanguage), $languageNameList); ksort($languageNameList); $this->view->languageNameList = $languageNameList; $this->_helper->layout->disableLayout(); // Render //$this -> _helper -> content //-> setNoRender() // -> setEnabled(); }
/** * @param string|null|Zend_Locale $locale * @param string $type * @throws InvalidArgumentException * @return array */ public static function getDaysWeek($locale, $type = 'wide') { if (!in_array($type, array('wide', 'abbreviated'))) { throw new InvalidArgumentException("Tipo inválido {$type}."); } $values = Zend_Locale_Data::getList($locale, 'day', array("gregorian", "format", $type)); return $values; }
public function formTinyMceYN($name, $value = null, $attribs = null) { // Disable for mobile browsers $ua = $_SERVER['HTTP_USER_AGENT']; if (preg_match('/Mobile/i', $ua) || preg_match('/Opera Mini/i', $ua) || preg_match('/NokiaN/i', $ua)) { return $this->formTextarea($name, $value, $attribs); } $info = $this->_getInfo($name, $value, $attribs); extract($info); // name, value, attribs, options, listsep, disable $disabled = ''; if ($disable) { $disabled = ' disabled="disabled"'; } if (Zend_Registry::isRegistered('Locale')) { $locale = Zend_Registry::get('Locale'); if (method_exists($locale, '__toString')) { $locale = $locale->__toString(); } else { $locale = (string) $locale; } $localeData = Zend_Locale_Data::getList($locale, 'layout'); $directionality = @$localeData['characters'] == 'right-to-left' ? 'rtl' : 'ltr'; //Checking SE version $manifest = Zend_Registry::get('Engine_Manifest'); if (version_compare($manifest['core']['package']['version'], '4.7.0', '<')) { $this->view->tinyMceYN()->language = $locale; $this->view->tinyMceYN()->directionality = $directionality; } else { $this->view->tinyMceYN1()->language = $locale; $this->view->tinyMceYN1()->directionality = $directionality; } } if (empty($attribs['rows'])) { $attribs['rows'] = (int) $this->rows; } if (empty($attribs['cols'])) { $attribs['cols'] = (int) $this->cols; } if (isset($attribs['editorOptions'])) { if ($attribs['editorOptions'] instanceof Zend_Config) { $attribs['editorOptions'] = $attribs['editorOptions']->toArray(); } if (version_compare($manifest['core']['package']['version'], '4.7.0', '<')) { $this->view->tinyMceYN()->setOptions($attribs['editorOptions']); } else { $this->view->tinyMceYN1()->setOptions($attribs['editorOptions']); } unset($attribs['editorOptions']); } if (version_compare($manifest['core']['package']['version'], '4.7.0', '<')) { $this->view->tinyMceYN()->render(); } else { $this->view->tinyMceYN1()->render(); } $xhtml = '<textarea rows=24, cols=80, style="width:553px;" name="' . $this->view->escape($name) . '"' . ' id="' . $this->view->escape($id) . '"' . $disabled . $this->_htmlAttribs($attribs) . '>' . $this->view->escape($value) . '</textarea>'; return $xhtml; }
/** * Set default time zone in the config file * * @param string The default time zone * @throw USVN_Exception */ public static function setTimeZone($timezone) { $availableTimezones = Zend_Locale_Data::getList("en", "WindowsToTimezone"); if (array_key_exists($timezone, $availableTimezones)) { $config = new USVN_Config_Ini(USVN_CONFIG_FILE, USVN_CONFIG_SECTION); $config->timezone = $timezone; $config->save(); } else { throw new USVN_Exception(T_("Invalid timezone")); } }
public function localeDateTime($format, $locale) { if (is_null($lang)) { $lang = ZFE_Core::getLanguage(); } $dt = new Zend_Date($this->getTimestamp()); $formats = Zend_Locale_Data::getList($lang, 'datetime'); if (isset($formats[$format])) { $format = $formats[$format]; } return $dt->toString($format, null, $lang); }
public function __construct($name, $title = null, $value = '', $maxLength = null, $form = null) { parent::__construct($name, $title, $value, $maxLength, $form); $this->setAlias(MaskedInputField::ALIAS_DECIMAL); $this->setDigits(2); $this->setRightAlign(false); // Some locale use "," as radix $locale = i18n::get_locale(); $symbols = Zend_Locale_Data::getList($locale, 'symbols'); if (!empty($symbols) && $symbols['decimal'] == ',') { $this->setRadixPoint(','); } }
public function indexAction() { $this->view->navigation = $navigation = Engine_Api::_()->getApi('menus', 'core')->getNavigation('core_footer'); // Languages $translate = Zend_Registry::get('Zend_Translate'); $languageList = $translate->getList(); //$currentLocale = Zend_Registry::get('Locale')->__toString(); // Prepare default langauge $defaultLanguage = Engine_Api::_()->getApi('settings', 'core')->getSetting('core.locale.locale', 'en'); if (!in_array($defaultLanguage, $languageList)) { if ($defaultLanguage == 'auto' && isset($languageList['en'])) { $defaultLanguage = 'en'; } else { $defaultLanguage = null; } } // Prepare language name list $languageNameList = array(); $languageDataList = Zend_Locale_Data::getList(null, 'language'); $territoryDataList = Zend_Locale_Data::getList(null, 'territory'); foreach ($languageList as $localeCode) { $languageNameList[$localeCode] = Engine_String::ucfirst(Zend_Locale::getTranslation($localeCode, 'language', $localeCode)); if (empty($languageNameList[$localeCode])) { if (false !== strpos($localeCode, '_')) { list($locale, $territory) = explode('_', $localeCode); } else { $locale = $localeCode; $territory = null; } if (isset($territoryDataList[$territory]) && isset($languageDataList[$locale])) { $languageNameList[$localeCode] = $territoryDataList[$territory] . ' ' . $languageDataList[$locale]; } else { if (isset($territoryDataList[$territory])) { $languageNameList[$localeCode] = $territoryDataList[$territory]; } else { if (isset($languageDataList[$locale])) { $languageNameList[$localeCode] = $languageDataList[$locale]; } else { continue; } } } } } $languageNameList = array_merge(array($defaultLanguage => $defaultLanguage), $languageNameList); $this->view->languageNameList = $languageNameList; // Get affiliate code $this->view->affiliateCode = Engine_Api::_()->getDbtable('settings', 'core')->core_affiliate_code; }
/** * Parses a Zend_Currency & Zend_Locale into a NostoCurrency object. * * REQUIRES Zend Framework (version 1) to be available. * * @param string $currencyCode the 3-letter ISO 4217 currency code. * @param Zend_Currency $zendCurrency the zend currency object. * @return NostoCurrency the parsed nosto currency object. * * @throws NostoInvalidArgumentException */ public function parseZendCurrencyFormat($currencyCode, Zend_Currency $zendCurrency) { try { $format = Zend_Locale_Data::getContent($zendCurrency->getLocale(), 'currencynumber'); $symbols = Zend_Locale_Data::getList($zendCurrency->getLocale(), 'symbols'); // Remove extra part, e.g. "¤ #,##0.00; (¤ #,##0.00)" => "¤ #,##0.00". if (($pos = strpos($format, ';')) !== false) { $format = substr($format, 0, $pos); } // Check if the currency symbol is before or after the amount. $symbolPosition = strpos(trim($format), '¤') === 0 ? NostoCurrencySymbol::SYMBOL_POS_LEFT : NostoCurrencySymbol::SYMBOL_POS_RIGHT; // Remove all other characters than "0", "#", "." and ",", $format = preg_replace('/[^0\\#\\.,]/', '', $format); // Calculate the decimal precision. $precision = 0; if (($decimalPos = strpos($format, '.')) !== false) { $precision = strlen($format) - (strrpos($format, '.') + 1); } else { $decimalPos = strlen($format); } $decimalFormat = substr($format, $decimalPos); if (($pos = strpos($decimalFormat, '#')) !== false) { $precision = strlen($decimalFormat) - $pos - $precision; } // Calculate the group length. if (strrpos($format, ',') !== false) { $groupLength = $decimalPos - strrpos($format, ',') - 1; } else { $groupLength = strrpos($format, '.'); } // If the symbol is missing for the current locale, use the ISO code. $currencySymbol = $zendCurrency->getSymbol(); if (is_null($currencySymbol)) { $currencySymbol = $currencyCode; } return new NostoCurrency(new NostoCurrencyCode($currencyCode), new NostoCurrencySymbol($currencySymbol, $symbolPosition), new NostoCurrencyFormat($symbols['group'], $groupLength, $symbols['decimal'], $precision)); } catch (Zend_Exception $e) { throw new NostoInvalidArgumentException($e); } }
/** * * @return array */ public function getFormat() { $row = $this->getData(); $currency = $this->getCurrency(); $position = $row['position']; if ($position == 8) { // Standard $position = $currency->toCurrency(1); $position = strpos($position, $currency->getSymbol()); if ($position) { $position = 'Right'; } else { $position = 'Left'; } } elseif ($position == 16) { $position = 'Right'; } else { $position = 'Left'; } $symbols = Zend_Locale_Data::getList($row['format'], 'symbols'); return array('precision' => $row['currency_precision'], 'requiredPrecision' => 2, 'integerRequired' => 1, 'decimalSymbol' => $symbols['decimal'], 'groupSymbol' => $symbols['group'], 'groupLength' => 3, 'position' => $position, 'symbol' => null === $currency->getSymbol() ? $currency->getShortName() : $currency->getSymbol(), 'shortName' => $currency->getShortName(), 'name' => $currency->getName(), 'display' => $row['display']); }
/** * Functions returns array with price formatting info for js function * formatCurrency in js/varien/js.js * * @return array */ public function getJsPriceFormat() { $format = Zend_Locale_Data::getContent($this->getLocaleCode(), 'currencynumber'); $symbols = Zend_Locale_Data::getList($this->getLocaleCode(), 'symbols'); $pos = strpos($format, ';'); if ($pos !== false) { $format = substr($format, 0, $pos); } $format = preg_replace("/[^0\\#\\.,]/", "", $format); $totalPrecision = 0; $decimalPoint = strpos($format, '.'); if ($decimalPoint !== false) { $totalPrecision = strlen($format) - (strrpos($format, '.') + 1); } else { $decimalPoint = strlen($format); } $requiredPrecision = $totalPrecision; $t = substr($format, $decimalPoint); $pos = strpos($t, '#'); if ($pos !== false) { $requiredPrecision = strlen($t) - $pos - $totalPrecision; } $group = 0; if (strrpos($format, ',') !== false) { $group = $decimalPoint - strrpos($format, ',') - 1; } else { $group = strrpos($format, '.'); } $integerRequired = strpos($format, '.') - strpos($format, '0'); //get the store id so you an correctly reference the global variable $store_id = Mage::app()->getStore()->getId(); //JASE get precision from custom variable that can be set at store level $getPrecision = Mage::getModel('core/variable')->setStoreId($store_id)->loadByCode('decimalPrecision')->getData('store_plain_value'); //if set use it, otherwise default to two decimals $totalPrecision = is_numeric($getPrecision) ? $getPrecision : $totalPrecision; $requiredPrecision = is_numeric($getPrecision) ? $getPrecision : $requiredPrecision; $result = array('pattern' => Mage::app()->getStore()->getCurrentCurrency()->getOutputFormat(), 'precision' => 0, 'requiredPrecision' => $requiredPrecision, 'decimalSymbol' => $symbols['decimal'], 'groupSymbol' => $symbols['group'], 'groupLength' => $group, 'integerRequired' => $integerRequired); return $result; }
/** * Parse date and split in named array fields * * @param string $date Date string to parse * @param array $options Options: format_type, fix_date, locale, date_format. See {@link setOptions()} for details. * @return array Possible array members: day, month, year, hour, minute, second, fixed, format */ private static function _parseDate($date, $options) { $options = array_merge(self::$_Options, self::checkOptions($options)); $test = array('h', 'H', 'm', 's', 'y', 'Y', 'M', 'd', 'D', 'E', 'S', 'l', 'B', 'I', 'X', 'r', 'U', 'G', 'w', 'e', 'a', 'A', 'Z', 'z', 'v'); $format = $options['date_format']; foreach (str_split($format) as $splitted) { if ((!in_array($splitted, $test)) and (ctype_alpha($splitted))) { require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("Unable to parse the date format string '" . $format . "' at letter '$splitted'"); } } $number = $date; // working copy $result['date_format'] = $format; // save the format used to normalize $number (convenience) $result['locale'] = $options['locale']; // save the locale used to normalize $number (convenience) $day = iconv_strpos($format, 'd'); $month = iconv_strpos($format, 'M'); $year = iconv_strpos($format, 'y'); $hour = iconv_strpos($format, 'H'); $min = iconv_strpos($format, 'm'); $sec = iconv_strpos($format, 's'); $am = null; if ($hour === false) { $hour = iconv_strpos($format, 'h'); } if ($year === false) { $year = iconv_strpos($format, 'Y'); } if ($day === false) { $day = iconv_strpos($format, 'E'); if ($day === false) { $day = iconv_strpos($format, 'D'); } } if ($day !== false) { $parse[$day] = 'd'; if (!empty($options['locale']) && ($options['locale'] !== 'root') && (!is_object($options['locale']) || ($options['locale']->toString() !== 'root'))) { // erase day string $daylist = Zend_Locale_Data::getList($options['locale'], 'day'); foreach($daylist as $key => $name) { if (iconv_strpos($number, $name) !== false) { $number = str_replace($name, "EEEE", $number); break; } } } } $position = false; if ($month !== false) { $parse[$month] = 'M'; if (!empty($options['locale']) && ($options['locale'] !== 'root') && (!is_object($options['locale']) || ($options['locale']->toString() !== 'root'))) { // prepare to convert month name to their numeric equivalents, if requested, // and we have a $options['locale'] $position = self::_replaceMonth($number, Zend_Locale_Data::getList($options['locale'], 'month')); if ($position === false) { $position = self::_replaceMonth($number, Zend_Locale_Data::getList($options['locale'], 'month', array('gregorian', 'format', 'abbreviated'))); } } } if ($year !== false) { $parse[$year] = 'y'; } if ($hour !== false) { $parse[$hour] = 'H'; } if ($min !== false) { $parse[$min] = 'm'; } if ($sec !== false) { $parse[$sec] = 's'; } if (empty($parse)) { require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("unknown date format, neither date nor time in '" . $format . "' found"); } ksort($parse); // get daytime if (iconv_strpos($format, 'a') !== false) { if (iconv_strpos(strtoupper($number), strtoupper(Zend_Locale_Data::getContent($options['locale'], 'am'))) !== false) { $am = true; } else if (iconv_strpos(strtoupper($number), strtoupper(Zend_Locale_Data::getContent($options['locale'], 'pm'))) !== false) { $am = false; } } // split number parts $split = false; preg_match_all('/\d+/u', $number, $splitted); if (count($splitted[0]) == 0) { require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("No date part in '$date' found."); } if (count($splitted[0]) == 1) { $split = 0; } $cnt = 0; foreach($parse as $key => $value) { switch($value) { case 'd': if ($split === false) { if (count($splitted[0]) > $cnt) { $result['day'] = $splitted[0][$cnt]; } } else { $result['day'] = iconv_substr($splitted[0][0], $split, 2); $split += 2; } ++$cnt; break; case 'M': if ($split === false) { if (count($splitted[0]) > $cnt) { $result['month'] = $splitted[0][$cnt]; } } else { $result['month'] = iconv_substr($splitted[0][0], $split, 2); $split += 2; } ++$cnt; break; case 'y': $length = 2; if ((iconv_substr($format, $year, 4) == 'yyyy') || (iconv_substr($format, $year, 4) == 'YYYY')) { $length = 4; } if ($split === false) { if (count($splitted[0]) > $cnt) { $result['year'] = $splitted[0][$cnt]; } } else { $result['year'] = iconv_substr($splitted[0][0], $split, $length); $split += $length; } ++$cnt; break; case 'H': if ($split === false) { if (count($splitted[0]) > $cnt) { $result['hour'] = $splitted[0][$cnt]; } } else { $result['hour'] = iconv_substr($splitted[0][0], $split, 2); $split += 2; } ++$cnt; break; case 'm': if ($split === false) { if (count($splitted[0]) > $cnt) { $result['minute'] = $splitted[0][$cnt]; } } else { $result['minute'] = iconv_substr($splitted[0][0], $split, 2); $split += 2; } ++$cnt; break; case 's': if ($split === false) { if (count($splitted[0]) > $cnt) { $result['second'] = $splitted[0][$cnt]; } } else { $result['second'] = iconv_substr($splitted[0][0], $split, 2); $split += 2; } ++$cnt; break; } } // AM/PM correction if ($hour !== false) { if (($am === true) and ($result['hour'] == 12)){ $result['hour'] = 0; } else if (($am === false) and ($result['hour'] != 12)) { $result['hour'] += 12; } } if ($options['fix_date'] === true) { $result['fixed'] = 0; // nothing has been "fixed" by swapping date parts around (yet) } if ($day !== false) { // fix false month if (isset($result['day']) and isset($result['month'])) { if (($position !== false) and ((iconv_strpos($date, $result['day']) === false) or (isset($result['year']) and (iconv_strpos($date, $result['year']) === false)))) { if ($options['fix_date'] !== true) { require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("unable to parse date '$date' using '" . $format . "' (false month, $position, $month)"); } $temp = $result['day']; $result['day'] = $result['month']; $result['month'] = $temp; $result['fixed'] = 1; } } // fix switched values d <> y if (isset($result['day']) and isset($result['year'])) { if ($result['day'] > 31) { if ($options['fix_date'] !== true) { require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("unable to parse date '$date' using '" . $format . "' (d <> y)"); } $temp = $result['year']; $result['year'] = $result['day']; $result['day'] = $temp; $result['fixed'] = 2; } } // fix switched values M <> y if (isset($result['month']) and isset($result['year'])) { if ($result['month'] > 31) { if ($options['fix_date'] !== true) { require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("unable to parse date '$date' using '" . $format . "' (M <> y)"); } $temp = $result['year']; $result['year'] = $result['month']; $result['month'] = $temp; $result['fixed'] = 3; } } // fix switched values M <> d if (isset($result['month']) and isset($result['day'])) { if ($result['month'] > 12) { if ($options['fix_date'] !== true || $result['month'] > 31) { require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("unable to parse date '$date' using '" . $format . "' (M <> d)"); } $temp = $result['day']; $result['day'] = $result['month']; $result['month'] = $temp; $result['fixed'] = 4; } } } return $result; }
/** * Returns the calculated month * * @param string $calc Calculation to make * @param string|integer|array|Zend_Date $month Month to calculate with, if null the actual month is taken * @param string|Zend_Locale $locale Locale for parsing input * @return integer|Zend_Date new time * @throws Zend_Date_Exception */ private function _month($calc, $month, $locale) { if ($month === null) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception('parameter $month must be set, null is not allowed'); } if ($locale === null) { $locale = $this->getLocale(); } if ($month instanceof Zend_Date) { // extract month from object $found = $month->toString(self::MONTH_SHORT, 'iso', $locale); } else { if (is_numeric($month)) { $found = $month; } else { if (is_array($month)) { if (isset($month['month']) === true) { $month = $month['month']; } else { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("no month given in array"); } } else { $monthlist = Zend_Locale_Data::getList($locale, 'month'); $monthlist2 = Zend_Locale_Data::getList($locale, 'month', array('gregorian', 'format', 'abbreviated')); $monthlist = array_merge($monthlist, $monthlist2); $found = 0; $cnt = 0; foreach ($monthlist as $key => $value) { if (strtoupper($value) == strtoupper($month)) { $found = $key % 12 + 1; break; } ++$cnt; } if ($found == 0) { foreach ($monthlist2 as $key => $value) { if (strtoupper(iconv_substr($value, 0, 1, 'UTF-8')) == strtoupper($month)) { $found = $key + 1; break; } ++$cnt; } } if ($found == 0) { require_once 'Zend/Date/Exception.php'; throw new Zend_Date_Exception("unknown month name ({$month})", 0, null, $month); } } } } $return = $this->_calcdetail($calc, $found, self::MONTH_SHORT, $locale); if ($calc != 'cmp') { return $this; } return $return; }
/** * returns number of the first day of the week (0 = sunday or 1 = monday) depending on locale * * @return integer */ protected function _getFirstDayOfWeek() { $locale = Tinebase_Core::getLocale(); $weekInfo = Zend_Locale_Data::getList($locale, 'week'); if (!isset($weekInfo['firstDay'])) { $result = 1; } else { $result = $weekInfo['firstDay'] === 'sun' ? 0 : 1; } return $result; }
/** * Returns localized informations as array, supported are several * types of informations. * Supported types are: * 'language', 'script', 'territory', 'variant', 'key', 'type', 'calendar', 'collation', * 'currency', 'layout', 'characters', 'delimiters', 'measurement', 'months', 'month', * 'days', 'day', 'week', 'quarters', 'quarter', 'eras', 'era', 'date', 'time', 'datetime', * 'field', 'relative', 'symbols', 'currency', 'currencysymbol', 'question', * 'currencyfraction', 'currencyrounding', 'currencytoregion', 'regiontocurrency', * 'regiontoterritory', 'territorytoregion', 'scripttolanguage', 'languagetoscript', * 'territorytolanguage', 'languagetoterritory', 'timezonetowindows', 'timezonetowindows', * 'territorytotimezone', 'timezonetoterritory', 'citytotimezone', 'timezonetocity' * For detailed information about the types look into the documentation * * @param string $path OPTIONAL Type of information to return * @param string|locale $locale OPTIONAL Locale|Language for which this informations should be returned * @param string $value OPTIONAL Value for detail list * @return array Array with the wished information in the given language */ public function getTranslationList($path = null, $locale = null, $value = null) { // load class within method for speed require_once 'Zend/Locale/Data.php'; require_once 'Zend/Locale/Exception.php'; if ($locale === null) { $locale = $this->_Locale; } if ($locale == 'auto') { $locale = self::$_auto; } if ($locale == 'browser') { $locale = self::$_browser; } if ($locale == 'environment') { $locale = self::$_environment; } if (is_array($locale)) { $locale = key($locale); } try { $result = Zend_Locale_Data::getList($locale, $path, $value); } catch (Zend_Locale_Exception $e) { return false; } if (empty($result)) { return false; } return $result; }
public function deleteAction() { $form = $this->view->form = new Core_Form_Admin_Language_Delete(); $languageList = Zend_Locale_Data::getList('en', 'language'); $territoryList = Zend_Locale_Data::getList('en', 'territory'); $localeCode = $this->_getParam('locale', null); if (empty($localeCode)) { return; } if (FALSE !== strpos($localeCode, '_')) { list($locale, $territory) = explode('_', $localeCode); } else { $locale = $localeCode; $territory = null; } $languagePack = $languageList[$locale]; if ($territory && !empty($territoryList[$territory])) { $languagePack .= " ({$territoryList[$territory]})"; } $languagePack .= " [{$localeCode}]"; $form->setDescription(sprintf($form->getDescription(), $languagePack)); if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) { $lang_dir = APPLICATION_PATH . '/application/languages/' . $localeCode; try { @Engine_Package_Utilities::fsRmdirRecursive($lang_dir, true); $this->_forward('success', 'utility', 'core', array('smoothboxClose' => 2000, 'parentRefresh' => 2000, 'format' => 'smoothbox', 'messages' => array(Zend_Registry::get('Zend_Translate')->_('Language has been deleted.')))); } catch (Exception $e) { $form->addError('Unable to delete language files. Please log in through FTP and delete the directory "/application/languages/' . $localeCode . '/ and all of the files inside.'); } } }
public function init() { $settings = Engine_Api::_()->getApi('settings', 'core'); $this->_emailAntispamEnabled = $settings->getSetting('core.spam.email.antispam.signup', 1) == 1 && empty($_SESSION['facebook_signup']) && empty($_SESSION['twitter_signup']) && empty($_SESSION['janrain_signup']); $inviteSession = new Zend_Session_Namespace('invite'); $tabIndex = 1; // Init form $this->setTitle('Create Account'); $this->setAttrib('id', 'signup_account_form'); // Element: name (trap) $this->addElement('Text', 'name', array('class' => 'signup-name', 'label' => 'Name', 'validators' => array(array('StringLength', true, array('max' => 0))))); $this->name->getValidator('StringLength')->setMessage('An error has occured, please try again later.'); // Element: email $emailElement = $this->addEmailElement(array('label' => 'Email Address', 'description' => 'You will use your email address to login.', 'required' => true, 'allowEmpty' => false, 'validators' => array(array('NotEmpty', true), array('EmailAddress', true), array('Db_NoRecordExists', true, array(Engine_Db_Table::getTablePrefix() . 'users', 'email'))), 'filters' => array('StringTrim'), 'inputType' => 'email', 'autofocus' => 'autofocus', 'tabindex' => $tabIndex++)); $emailElement->getDecorator('Description')->setOptions(array('placement' => 'APPEND')); $emailElement->getValidator('NotEmpty')->setMessage('Please enter a valid email address.', 'isEmpty'); $emailElement->getValidator('Db_NoRecordExists')->setMessage('Someone has already registered this email address, please use another one.', 'recordFound'); $emailElement->getValidator('EmailAddress')->getHostnameValidator()->setValidateTld(false); // Add banned email validator $bannedEmailValidator = new Engine_Validate_Callback(array($this, 'checkBannedEmail'), $emailElement); $bannedEmailValidator->setMessage("This email address is not available, please use another one."); $emailElement->addValidator($bannedEmailValidator); if (!empty($inviteSession->invite_email)) { $emailElement->setValue($inviteSession->invite_email); } //if( $settings->getSetting('user.signup.verifyemail', 0) > 0 && $settings->getSetting('user.signup.checkemail', 0) == 1 ) { // $this->email->addValidator('Identical', true, array($inviteSession->invite_email)); // $this->email->getValidator('Identical')->setMessage('Your email address must match the address that was invited.', 'notSame'); //} // Element: code if ($settings->getSetting('user.signup.inviteonly') > 0) { $codeValidator = new Engine_Validate_Callback(array($this, 'checkInviteCode'), $emailElement); $codeValidator->setMessage("This invite code is invalid or does not match the selected email address"); $this->addElement('Text', 'code', array('label' => 'Invite Code', 'required' => true)); $this->code->addValidator($codeValidator); if (!empty($inviteSession->invite_code)) { $this->code->setValue($inviteSession->invite_code); } } if ($settings->getSetting('user.signup.random', 0) == 0 && empty($_SESSION['facebook_signup']) && empty($_SESSION['twitter_signup']) && empty($_SESSION['janrain_signup'])) { // Element: password $this->addElement('Password', 'password', array('label' => 'Password', 'description' => 'Passwords must be at least 6 characters in length.', 'required' => true, 'allowEmpty' => false, 'validators' => array(array('NotEmpty', true), array('StringLength', false, array(6, 32))), 'tabindex' => $tabIndex++)); $this->password->getDecorator('Description')->setOptions(array('placement' => 'APPEND')); $this->password->getValidator('NotEmpty')->setMessage('Please enter a valid password.', 'isEmpty'); // Element: passconf $this->addElement('Password', 'passconf', array('label' => 'Password Again', 'description' => 'Enter your password again for confirmation.', 'required' => true, 'validators' => array(array('NotEmpty', true)), 'tabindex' => $tabIndex++)); $this->passconf->getDecorator('Description')->setOptions(array('placement' => 'APPEND')); $this->passconf->getValidator('NotEmpty')->setMessage('Please make sure the "password" and "password again" fields match.', 'isEmpty'); $specialValidator = new Engine_Validate_Callback(array($this, 'checkPasswordConfirm'), $this->password); $specialValidator->setMessage('Password did not match', 'invalid'); $this->passconf->addValidator($specialValidator); } // Element: username if ($settings->getSetting('user.signup.username', 1) > 0) { $description = Zend_Registry::get('Zend_Translate')->_('This will be the end of your profile link, for example: <br /> ' . '<span id="profile_address">http://%s</span>'); $description = sprintf($description, $_SERVER['HTTP_HOST'] . Zend_Controller_Front::getInstance()->getRouter()->assemble(array('id' => 'yourname'), 'user_profile')); $this->addElement('Text', 'username', array('label' => 'Profile Address', 'description' => $description, 'required' => true, 'allowEmpty' => false, 'validators' => array(array('NotEmpty', true), array('Alnum', true), array('StringLength', true, array(4, 64)), array('Regex', true, array('/^[a-z][a-z0-9]*$/i')), array('Db_NoRecordExists', true, array(Engine_Db_Table::getTablePrefix() . 'users', 'username'))), 'tabindex' => $tabIndex++)); $this->username->getDecorator('Description')->setOptions(array('placement' => 'APPEND', 'escape' => false)); $this->username->getValidator('NotEmpty')->setMessage('Please enter a valid profile address.', 'isEmpty'); $this->username->getValidator('Db_NoRecordExists')->setMessage('Someone has already picked this profile address, please use another one.', 'recordFound'); $this->username->getValidator('Regex')->setMessage('Profile addresses must start with a letter.', 'regexNotMatch'); $this->username->getValidator('Alnum')->setMessage('Profile addresses must be alphanumeric.', 'notAlnum'); // Add banned username validator $bannedUsernameValidator = new Engine_Validate_Callback(array($this, 'checkBannedUsername'), $this->username); $bannedUsernameValidator->setMessage("This profile address is not available, please use another one."); $this->username->addValidator($bannedUsernameValidator); } // Element: profile_type $topStructure = Engine_Api::_()->fields()->getFieldStructureTop('user'); if (count($topStructure) == 1 && $topStructure[0]->getChild()->type == 'profile_type') { $profileTypeField = $topStructure[0]->getChild(); $options = $profileTypeField->getOptions(); if (count($options) > 1) { $options = $profileTypeField->getElementParams('user'); unset($options['options']['order']); unset($options['options']['multiOptions']['0']); $this->addElement('Select', 'profile_type', array_merge($options['options'], array('required' => true, 'allowEmpty' => false, 'tabindex' => $tabIndex++))); } else { if (count($options) == 1) { $this->addElement('Hidden', 'profile_type', array('value' => $options[0]->option_id)); } } } // Element: timezone $this->addElement('Select', 'timezone', array('label' => 'Timezone', 'value' => $settings->getSetting('core.locale.timezone'), 'multiOptions' => array('US/Pacific' => '(UTC-8) Pacific Time (US & Canada)', 'US/Mountain' => '(UTC-7) Mountain Time (US & Canada)', 'US/Central' => '(UTC-6) Central Time (US & Canada)', 'US/Eastern' => '(UTC-5) Eastern Time (US & Canada)', 'America/Halifax' => '(UTC-4) Atlantic Time (Canada)', 'America/Anchorage' => '(UTC-9) Alaska (US & Canada)', 'Pacific/Honolulu' => '(UTC-10) Hawaii (US)', 'Pacific/Samoa' => '(UTC-11) Midway Island, Samoa', 'Etc/GMT-12' => '(UTC-12) Eniwetok, Kwajalein', 'Canada/Newfoundland' => '(UTC-3:30) Canada/Newfoundland', 'America/Buenos_Aires' => '(UTC-3) Brasilia, Buenos Aires, Georgetown', 'Atlantic/South_Georgia' => '(UTC-2) Mid-Atlantic', 'Atlantic/Azores' => '(UTC-1) Azores, Cape Verde Is.', 'Europe/London' => 'Greenwich Mean Time (Lisbon, London)', 'Europe/Berlin' => '(UTC+1) Amsterdam, Berlin, Paris, Rome, Madrid', 'Europe/Athens' => '(UTC+2) Athens, Helsinki, Istanbul, Cairo, E. Europe', 'Europe/Moscow' => '(UTC+3) Baghdad, Kuwait, Nairobi, Moscow', 'Iran' => '(UTC+3:30) Tehran', 'Asia/Dubai' => '(UTC+4) Abu Dhabi, Kazan, Muscat', 'Asia/Kabul' => '(UTC+4:30) Kabul', 'Asia/Yekaterinburg' => '(UTC+5) Islamabad, Karachi, Tashkent', 'Asia/Calcutta' => '(UTC+5:30) Bombay, Calcutta, New Delhi', 'Asia/Katmandu' => '(UTC+5:45) Nepal', 'Asia/Omsk' => '(UTC+6) Almaty, Dhaka', 'Indian/Cocos' => '(UTC+6:30) Cocos Islands, Yangon', 'Asia/Krasnoyarsk' => '(UTC+7) Bangkok, Jakarta, Hanoi', 'Asia/Hong_Kong' => '(UTC+8) Beijing, Hong Kong, Singapore, Taipei', 'Asia/Tokyo' => '(UTC+9) Tokyo, Osaka, Sapporto, Seoul, Yakutsk', 'Australia/Adelaide' => '(UTC+9:30) Adelaide, Darwin', 'Australia/Sydney' => '(UTC+10) Brisbane, Melbourne, Sydney, Guam', 'Asia/Magadan' => '(UTC+11) Magadan, Solomon Is., New Caledonia', 'Pacific/Auckland' => '(UTC+12) Fiji, Kamchatka, Marshall Is., Wellington'), 'tabindex' => $tabIndex++)); $this->timezone->getDecorator('Description')->setOptions(array('placement' => 'APPEND')); // Element: language // Languages $translate = Zend_Registry::get('Zend_Translate'); $languageList = $translate->getList(); //$currentLocale = Zend_Registry::get('Locale')->__toString(); // Prepare default langauge $defaultLanguage = Engine_Api::_()->getApi('settings', 'core')->getSetting('core.locale.locale', 'en'); if (!in_array($defaultLanguage, $languageList)) { if ($defaultLanguage == 'auto' && isset($languageList['en'])) { $defaultLanguage = 'en'; } else { $defaultLanguage = null; } } // Prepare language name list $localeObject = Zend_Registry::get('Locale'); $languageNameList = array(); $languageDataList = Zend_Locale_Data::getList($localeObject, 'language'); $territoryDataList = Zend_Locale_Data::getList($localeObject, 'territory'); foreach ($languageList as $localeCode) { $languageNameList[$localeCode] = Zend_Locale::getTranslation($localeCode, 'language', $localeCode); if (empty($languageNameList[$localeCode])) { list($locale, $territory) = explode('_', $localeCode); $languageNameList[$localeCode] = "{$territoryDataList[$territory]} {$languageDataList[$locale]}"; } } $languageNameList = array_merge(array($defaultLanguage => $defaultLanguage), $languageNameList); if (count($languageNameList) > 1) { $this->addElement('Select', 'language', array('label' => 'Language', 'multiOptions' => $languageNameList, 'tabindex' => $tabIndex++)); $this->language->getDecorator('Description')->setOptions(array('placement' => 'APPEND')); } else { $this->addElement('Hidden', 'language', array('value' => current((array) $languageNameList))); } // Element: captcha if (Engine_Api::_()->getApi('settings', 'core')->core_spam_signup) { $this->addElement('captcha', 'captcha', Engine_Api::_()->core()->getCaptchaOptions(array('tabindex' => $tabIndex++))); } if ($settings->getSetting('user.signup.terms', 1) == 1) { // Element: terms $description = Zend_Registry::get('Zend_Translate')->_('I have read and agree to the <a target="_blank" href="%s/help/terms">terms of service</a>.'); $description = sprintf($description, Zend_Controller_Front::getInstance()->getBaseUrl()); $this->addElement('Checkbox', 'terms', array('label' => 'Terms of Service', 'description' => $description, 'required' => true, 'validators' => array('notEmpty', array('GreaterThan', false, array(0))), 'tabindex' => $tabIndex++)); $this->terms->getValidator('GreaterThan')->setMessage('You must agree to the terms of service to continue.', 'notGreaterThan'); //$this->terms->getDecorator('Label')->setOption('escape', false); $this->terms->clearDecorators()->addDecorator('ViewHelper')->addDecorator('Description', array('placement' => Zend_Form_Decorator_Abstract::APPEND, 'tag' => 'label', 'class' => 'null', 'escape' => false, 'for' => 'terms'))->addDecorator('DivDivDivWrapper'); //$this->terms->setDisableTranslator(true); } // Init submit $this->addElement('Button', 'submit', array('label' => 'Continue', 'type' => 'submit', 'ignore' => true, 'tabindex' => $tabIndex++)); if (empty($_SESSION['facebook_signup'])) { // Init facebook login link // if( 'none' != $settings->getSetting('core_facebook_enable', 'none') // && $settings->core_facebook_secret ) { // $this->addElement('Dummy', 'facebook', array( // 'content' => User_Model_DbTable_Facebook::loginButton(), // )); // } } if (empty($_SESSION['twitter_signup'])) { // Init twitter login link // if( 'none' != $settings->getSetting('core_twitter_enable', 'none') // && $settings->core_twitter_secret ) { // $this->addElement('Dummy', 'twitter', array( // 'content' => User_Model_DbTable_Twitter::loginButton(), // )); // } } // Set default action $this->setAction(Zend_Controller_Front::getInstance()->getRouter()->assemble(array(), 'user_signup', true)); }
/** * Parse date and split in named array fields * * @param string $date Date string to parse * @param array $options Options: format_type, fix_date, locale, date_format. See {@link setOptions()} for details. * @return array Possible array members: day, month, year, hour, minute, second, fixed, format */ private static function _parseDate($date, $options) { if (!self::_getUniCodeSupport()) { trigger_error("Sorry, your PCRE extension does not support UTF8 which is needed for the I18N core", E_USER_NOTICE); } $options = self::_checkOptions($options) + self::$_options; $test = array('h', 'H', 'm', 's', 'y', 'Y', 'M', 'd', 'D', 'E', 'S', 'l', 'B', 'I', 'X', 'r', 'U', 'G', 'w', 'e', 'a', 'A', 'Z', 'z', 'v'); $format = $options['date_format']; $number = $date; // working copy $result['date_format'] = $format; // save the format used to normalize $number (convenience) $result['locale'] = $options['locale']; // save the locale used to normalize $number (convenience) $oenc = iconv_get_encoding('internal_encoding'); iconv_set_encoding('internal_encoding', 'UTF-8'); $day = iconv_strpos($format, 'd'); $month = iconv_strpos($format, 'M'); $year = iconv_strpos($format, 'y'); $hour = iconv_strpos($format, 'H'); $min = iconv_strpos($format, 'm'); $sec = iconv_strpos($format, 's'); $am = null; if ($hour === false) { $hour = iconv_strpos($format, 'h'); } if ($year === false) { $year = iconv_strpos($format, 'Y'); } if ($day === false) { $day = iconv_strpos($format, 'E'); if ($day === false) { $day = iconv_strpos($format, 'D'); } } if ($day !== false) { $parse[$day] = 'd'; if (!empty($options['locale']) && $options['locale'] !== 'root' && (!is_object($options['locale']) || (string) $options['locale'] !== 'root')) { // erase day string $daylist = Zend_Locale_Data::getList($options['locale'], 'day'); foreach ($daylist as $key => $name) { if (iconv_strpos($number, $name) !== false) { $number = str_replace($name, "EEEE", $number); break; } } } } $position = false; if ($month !== false) { $parse[$month] = 'M'; if (!empty($options['locale']) && $options['locale'] !== 'root' && (!is_object($options['locale']) || (string) $options['locale'] !== 'root')) { // prepare to convert month name to their numeric equivalents, if requested, // and we have a $options['locale'] $position = self::_replaceMonth($number, Zend_Locale_Data::getList($options['locale'], 'month')); if ($position === false) { $position = self::_replaceMonth($number, Zend_Locale_Data::getList($options['locale'], 'month', array('gregorian', 'format', 'abbreviated'))); } } } if ($year !== false) { $parse[$year] = 'y'; } if ($hour !== false) { $parse[$hour] = 'H'; } if ($min !== false) { $parse[$min] = 'm'; } if ($sec !== false) { $parse[$sec] = 's'; } if (empty($parse)) { iconv_set_encoding('internal_encoding', $oenc); // require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("Unknown date format, neither date nor time in '" . $format . "' found"); } ksort($parse); // get daytime if (iconv_strpos($format, 'a') !== false) { if (iconv_strpos(strtoupper($number), strtoupper(Zend_Locale_Data::getContent($options['locale'], 'am'))) !== false) { $am = true; } else { if (iconv_strpos(strtoupper($number), strtoupper(Zend_Locale_Data::getContent($options['locale'], 'pm'))) !== false) { $am = false; } } } // split number parts $split = false; preg_match_all('/\\d+/u', $number, $splitted); if (count($splitted[0]) == 0) { iconv_set_encoding('internal_encoding', $oenc); // require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("No date part in '{$date}' found."); } if (count($splitted[0]) == 1) { $split = 0; } $cnt = 0; foreach ($parse as $key => $value) { switch ($value) { case 'd': if ($split === false) { if (count($splitted[0]) > $cnt) { $result['day'] = $splitted[0][$cnt]; } } else { $result['day'] = iconv_substr($splitted[0][0], $split, 2); $split += 2; } ++$cnt; break; case 'M': if ($split === false) { if (count($splitted[0]) > $cnt) { $result['month'] = $splitted[0][$cnt]; } } else { $result['month'] = iconv_substr($splitted[0][0], $split, 2); $split += 2; } ++$cnt; break; case 'y': $length = 2; if (iconv_substr($format, $year, 4) == 'yyyy' || iconv_substr($format, $year, 4) == 'YYYY') { $length = 4; } if ($split === false) { if (count($splitted[0]) > $cnt) { $result['year'] = $splitted[0][$cnt]; } } else { $result['year'] = iconv_substr($splitted[0][0], $split, $length); $split += $length; } ++$cnt; break; case 'H': if ($split === false) { if (count($splitted[0]) > $cnt) { $result['hour'] = $splitted[0][$cnt]; } } else { $result['hour'] = iconv_substr($splitted[0][0], $split, 2); $split += 2; } ++$cnt; break; case 'm': if ($split === false) { if (count($splitted[0]) > $cnt) { $result['minute'] = $splitted[0][$cnt]; } } else { $result['minute'] = iconv_substr($splitted[0][0], $split, 2); $split += 2; } ++$cnt; break; case 's': if ($split === false) { if (count($splitted[0]) > $cnt) { $result['second'] = $splitted[0][$cnt]; } } else { $result['second'] = iconv_substr($splitted[0][0], $split, 2); $split += 2; } ++$cnt; break; } } // AM/PM correction if ($hour !== false) { if ($am === true and $result['hour'] == 12) { $result['hour'] = 0; } else { if ($am === false and $result['hour'] != 12) { $result['hour'] += 12; } } } if ($options['fix_date'] === true) { $result['fixed'] = 0; // nothing has been "fixed" by swapping date parts around (yet) } if ($day !== false) { // fix false month if (isset($result['day']) and isset($result['month'])) { if ($position !== false and (iconv_strpos($date, $result['day']) === false or isset($result['year']) and iconv_strpos($date, $result['year']) === false)) { if ($options['fix_date'] !== true) { iconv_set_encoding('internal_encoding', $oenc); // require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("Unable to parse date '{$date}' using '" . $format . "' (false month, {$position}, {$month})"); } $temp = $result['day']; $result['day'] = $result['month']; $result['month'] = $temp; $result['fixed'] = 1; } } // fix switched values d <> y if (isset($result['day']) and isset($result['year'])) { if ($result['day'] > 31) { if ($options['fix_date'] !== true) { iconv_set_encoding('internal_encoding', $oenc); // require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("Unable to parse date '{$date}' using '" . $format . "' (d <> y)"); } $temp = $result['year']; $result['year'] = $result['day']; $result['day'] = $temp; $result['fixed'] = 2; } } // fix switched values M <> y if (isset($result['month']) and isset($result['year'])) { if ($result['month'] > 31) { if ($options['fix_date'] !== true) { iconv_set_encoding('internal_encoding', $oenc); // require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("Unable to parse date '{$date}' using '" . $format . "' (M <> y)"); } $temp = $result['year']; $result['year'] = $result['month']; $result['month'] = $temp; $result['fixed'] = 3; } } // fix switched values M <> d if (isset($result['month']) and isset($result['day'])) { if ($result['month'] > 12) { if ($options['fix_date'] !== true || $result['month'] > 31) { iconv_set_encoding('internal_encoding', $oenc); // require_once 'Zend/Locale/Exception.php'; throw new Zend_Locale_Exception("Unable to parse date '{$date}' using '" . $format . "' (M <> d)"); } $temp = $result['day']; $result['day'] = $result['month']; $result['month'] = $temp; $result['fixed'] = 4; } } } if (isset($result['year'])) { if (iconv_strlen($result['year']) == 2 && $result['year'] < 10 || (iconv_strpos($format, 'yy') !== false && iconv_strpos($format, 'yyyy') === false || iconv_strpos($format, 'YY') !== false && iconv_strpos($format, 'YYYY') === false)) { if ($result['year'] >= 0 && $result['year'] < 100) { if ($result['year'] < 70) { $result['year'] = (int) $result['year'] + 100; } $result['year'] = (int) $result['year'] + 1900; } } } iconv_set_encoding('internal_encoding', $oenc); return $result; }
public static function getJsPriceFormat($store = null) { if (!$store instanceof Mage_Core_Model_Store) { return Mage::app()->getLocale()->getJsPriceFormat(); } $format = Zend_Locale_Data::getContent(self::getLocaleCode($store), 'currencynumber'); $symbols = Zend_Locale_Data::getList(self::getLocaleCode($store), 'symbols'); $pos = strpos($format, ';'); if ($pos !== false) { $format = substr($format, 0, $pos); } $format = preg_replace("/[^0\\#\\.,]/", "", $format); $totalPrecision = 0; $decimalPoint = strpos($format, '.'); if ($decimalPoint !== false) { $totalPrecision = strlen($format) - (strrpos($format, '.') + 1); } else { $decimalPoint = strlen($format); } $requiredPrecision = $totalPrecision; $t = substr($format, $decimalPoint); $pos = strpos($t, '#'); if ($pos !== false) { $requiredPrecision = strlen($t) - $pos - $totalPrecision; } $group = 0; if (strrpos($format, ',') !== false) { $group = $decimalPoint - strrpos($format, ',') - 1; } else { $group = strrpos($format, '.'); } $integerRequired = strpos($format, '.') - strpos($format, '0'); $result = array('pattern' => $store->getCurrentCurrency()->getOutputFormat(), 'precision' => $totalPrecision, 'requiredPrecision' => $requiredPrecision, 'decimalSymbol' => $symbols['decimal'], 'groupSymbol' => $symbols['group'], 'groupLength' => $group, 'integerRequired' => $integerRequired); return $result; }
/** * Returns a list of currencies which are used in this region * a region name should be 2 charachters only (f.e. EG, DE, US) * If no region is given, the actual region is used * * @param string $region OPTIONAL Region to return the currencies for * @return array List of currencies */ public function getCurrencyList($region = null) { if (empty($region) === true) { if (strlen($this->_locale) > 4) { $region = substr($this->_locale, strpos($this->_locale, '_') + 1); } } return Zend_Locale_Data::getList('', 'regiontocurrency', $region); }
public function init() { $this->setTitle('Translate Language')->setDescription('Translate a language pack using Google Translate.')->setAction(Zend_Controller_Front::getInstance()->getRouter()->assemble(array())); // Build language list $translate = Zend_Registry::get('Zend_Translate'); //$translate = new Zend_Translate_Adapter(); $languageList = Zend_Locale_Data::getList('en', 'language'); $territoryList = Zend_Locale_Data::getList('en', 'territory'); //var_dump(array_intersect(Engine_Service_GTranslate::getAvailableLanguages(), array_keys($languageList))); //var_dump(array_diff(Engine_Service_GTranslate::getAvailableLanguages(), array_keys($languageList))); //var_dump(array_diff(array_keys($languageList), Engine_Service_GTranslate::getAvailableLanguages())); //die(); $languageNameList = array(); foreach (array_keys(Zend_Locale::getLocaleList()) as $localeCode) { $lang_array = explode('_', $localeCode); $locale = array_shift($lang_array); $territory = array_shift($lang_array); // Full locale $languageName = null; if (isset($languageList[$localeCode])) { $languageName = $languageList[$locale] . ' [' . $localeCode . ']'; } else { if (isset($languageList[$locale])) { $languageName = $languageList[$locale]; if (!empty($territoryList[$territory])) { $languageName .= ' (' . $territoryList[$territory] . ')'; } $languageName .= ' [' . $localeCode . ']'; } else { //$languageName = '[' . $localeCode . ']'; } } // Check against gtranslate if (!Engine_Service_GTranslate::isAvailableLanguage($localeCode)) { continue; //} else if( !Engine_Service_GTranslate::testAvailableLanguage($localeCode) ) { // echo 'Bad: ' . $localeCode . '<br />' . PHP_EOL; // continue; //} else { // echo 'Good: ' . $localeCode . '<br />' . PHP_EOL; } if ($languageName) { $languageNameList[$localeCode] = $languageName; } } asort($languageNameList); // Let's pull the existing languages to the top? $existingLanguageNameList = array(); $notExistingLanguageNameList = array(); foreach ($translate->getList() as $locale) { if (isset($languageNameList[$locale])) { $existingLanguageNameList[$locale] = $languageNameList[$locale]; } } $notExistingLanguageNameList = array_diff_key($languageNameList, $existingLanguageNameList); //$languageNameList = array_merge($existingLanguageNameList, $languageNameList); $targetMultiOptions = array_merge($existingLanguageNameList, $notExistingLanguageNameList); $targetMultiOptions = array('Translated' => $existingLanguageNameList, 'Untranslated' => $notExistingLanguageNameList, 'Special' => array('all' => 'All Available', 'all-translated' => 'All Translated', 'all-untranslated' => 'All Untranslated')); // Element: source $this->addElement('Select', 'source', array('label' => 'Source language', 'value' => 'en', 'required' => true, 'allowEmpty' => false)); foreach ($translate->getList() as $locale) { if (!Engine_Service_GTranslate::isAvailableLanguage($locale)) { continue; } $this->source->addMultiOption($locale, @$languageNameList[$locale] ? $languageNameList[$locale] : $locale); } // Element: target $this->addElement('Select', 'target', array('label' => 'Target Language', 'multiOptions' => array_merge(array('' => ''), $targetMultiOptions), 'required' => true, 'allowEmpty' => false)); // Element: batchCount $this->addElement('Text', 'batchCount', array('label' => 'Batch Count', 'allowEmpty' => false, 'validators' => array('Int'), 'value' => 50)); // Element: overwrite $this->addElement('Radio', 'overwrite', array('label' => 'Retranslate', 'description' => 'Do you want to retranslate existing phrases?', 'multiOptions' => array('1' => 'Yes', '0' => 'No'), 'value' => '0')); // Element: test $this->addElement('Text', 'test', array('label' => 'Test Translation', 'description' => 'Test Translation')); // Element: submit $this->addElement('Button', 'submit', array('label' => 'Translate', 'type' => 'submit', 'decorators' => array('ViewHelper'))); // Element: cancel $this->addElement('Cancel', 'cancel', array('prependText' => ' or ', 'link' => true, 'label' => 'cancel', 'onclick' => 'history.go(-1); return false;', 'decorators' => array('ViewHelper'))); // DisplayGroup: buttons $this->addDisplayGroup(array('submit', 'cancel'), 'buttons'); }
/** * Returns an array with translated yes strings * * @param string|Zend_Locale $locale (Optional) Locale for language translation (defaults to $this locale) * @return array */ public static function getQuestion($locale = null) { require_once 'Zend/Locale/Data.php'; $locale = self::findLocale($locale); $quest = Zend_Locale_Data::getList($locale, 'question'); $yes = explode(':', $quest['yes']); $no = explode(':', $quest['no']); $quest['yes'] = $yes[0]; $quest['yesarray'] = $yes; $quest['no'] = $no[0]; $quest['noarray'] = $no; $quest['yesexpr'] = self::_prepareQuestionString($yes); $quest['noexpr'] = self::_prepareQuestionString($no); return $quest; }
/** * Get the decimal separator * * @param string $locale Which locale is to be used to determine the value. * If not set, fall back to UI locale. If UI locale is not set, fall back to "en_US" * @return string The separator */ function caGetDecimalSeparator($locale = null) { if (!$locale) { global $g_ui_locale; $locale = $g_ui_locale; if (!$locale) { $locale = 'en_US'; } } $va_symbols = Zend_Locale_Data::getList($locale, 'symbols'); if (isset($va_symbols['decimal'])) { return $va_symbols['decimal']; } else { return '.'; } }
/** * Returns the script direction in format compatible with the HTML "dir" attribute. * * @see http://www.w3.org/International/tutorials/bidi-xhtml/ * @param String $locale Optional locale incl. region (underscored) * @return String "rtl" or "ltr" */ public static function get_script_direction($locale = null) { require_once 'Zend/Locale/Data.php'; if (!$locale) { $locale = i18n::get_locale(); } try { $dir = Zend_Locale_Data::getList($locale, 'layout'); } catch (Zend_Locale_Exception $e) { $dir = Zend_Locale_Data::getList(i18n::get_lang_from_locale($locale), 'layout'); } return $dir && $dir['characters'] == 'right-to-left' ? 'rtl' : 'ltr'; }
/** * This method will write the choosen timezone into config file. * * Throw an exception in case of problems. * * @param string Path to the USVN config file * @param string Language * @throw USVN_Exception */ public static function installTimezone($config_file, $timezone) { $availableTimeZones = Zend_Locale_Data::getList('en', 'WindowsToTimezone'); if (array_key_exists($timezone, $availableTimeZones)) { $config = Install::_loadConfig($config_file); $config->timezone = $timezone; $config->save(); } else { throw new USVN_Exception(T_('Invalid timezone')); } }