public function render(Zend_View_Interface $view = null) { if ($this->getLocalization()) { if (!$view) { $view = Zend_Layout::getMvcInstance()->getView(); } if (Zmz_Culture::getLanguage() != 'en') { // ignore english translations $view->headScript()->appendFile($this->getJqueryI18nDirectory() . '/jquery.ui.datepicker-' . Zmz_Culture::getLanguage() . '.js'); } } return parent::render($view); }
public static function getHowLongAgo(Zend_Date $date, $ago = 'ago') { $howLongAgo = ""; $locale = Zmz_Culture::getLocale(); $unitArray = Zend_Locale::getTranslationList('Unit'); $display = array(0 => $unitArray['duration-year'], 1 => $unitArray['duration-month'], 2 => $unitArray['duration-day'], 3 => $unitArray['duration-hour'], 4 => $unitArray['duration-minute'], 5 => $unitArray['duration-second']); $eventTimestamp = $date->getTimestamp(); $totaldelay = time() - $eventTimestamp; $value = 0; $unit = null; if ($totaldelay <= 0) { return ''; } $array = array(0 => 31536000, 1 => 2678400, 2 => 86400, 3 => 3600, 4 => 60, 5 => 1); foreach ($array as $k => $v) { $value = floor($totaldelay / $v); if ($value) { $totaldelay = $totaldelay % $v; $unit = $k; break; } } if ($value && $unit !== null) { $baseString = $value > 1 ? @$display[$unit]['other'] : @$display[$unit]['one']; if ($ago) { $ago = ' ' . $ago; } $howLongAgo = Zmz_String::format($baseString, $value) . $ago; } return $howLongAgo; }
public static function getCountryLanguages() { if (!self::$countryLanguages) { $locales = Zend_Locale::getLocaleList(); $enLocale = new Zend_Locale('en'); $countries = array(); foreach ($locales as $k => $v) { $tmpLocale = new Zend_Locale($k); $region = $tmpLocale->getRegion(); try { $countryName = Zend_Locale::getTranslation($region, 'Territory', self::getLocale()); if (!trim($countryName)) { throw new Zmz_Culture_Exception('No translation for current locale'); } } catch (Exception $e) { $countryName = Zend_Locale::getTranslation($region, 'Territory', $enLocale); } if (!trim($countryName)) { continue; } try { $languageTranslation = Zend_Locale::getTranslation($tmpLocale->getLanguage(), 'language', self::getLocale()); if (!trim($languageTranslation)) { throw new Zmz_Culture_Exception('No translation for current locale'); } } catch (Exception $e) { $languageTranslation = Zend_Locale::getTranslation($tmpLocale->getLanguage(), 'language', $enLocale); } if (!trim($languageTranslation)) { continue; } if (!isset($countries[$region])) { $countries[$region] = array('name' => $countryName, 'locales' => array()); } $countries[$region]['locales'][$k] = $languageTranslation; } self::$countryLanguages = $countries; } return self::$countryLanguages; }
public static function getHowLongAgo($date, $ago = 'ago') { $locale = Zmz_Culture::getLocale(); $unit = Zend_Locale::getTranslationList('Unit'); $display = array(0 => $unit['year'], 1 => $unit['month'], 2 => $unit['day'], 3 => $unit['hour'], 4 => $unit['minute'], 5 => $unit['second']); $givenDate = clone $date; $givenDate = self::toUTC($givenDate); $now = self::toUTC(); if ($givenDate->isLater($now)) { return ''; } $dateCompare = getdate($givenDate->getTimestamp()); $current = getdate($now->getTimestamp()); $p = array('year', 'mon', 'mday', 'hours', 'minutes', 'seconds'); $factor = array(0, 12, 30, 24, 60, 60); for ($i = 0; $i < 6; $i++) { if ($i > 0) { $current[$p[$i]] += $current[$p[$i - 1]] * $factor[$i]; $dateCompare[$p[$i]] += $dateCompare[$p[$i - 1]] * $factor[$i]; } if ($current[$p[$i]] - $dateCompare[$p[$i]] >= 1) { $value = $current[$p[$i]] - $dateCompare[$p[$i]]; $string = str_replace('{0}', $value, $value != 1 ? $display[$i]['other'] : $display[$i]['one']) . ' ' . $ago; return $string; } } $diffDates = $now->sub($givenDate); $value = (int) $diffDates->get(Zend_Date::SECOND_SHORT); return str_replace('{0}', $value, $value != 1 ? $display[5]['other'] : $display[5]['one']) . ' ' . $ago; }