示例#1
0
 public function preDispatch(Zend_Controller_Request_Abstract $request)
 {
     if (null !== ($locale = $request->getParam('locale'))) {
         if (strtoupper($locale) === 'NULL') {
             setcookie('openskos_locale', '', time() - 3600, '/');
             $this->_redirect();
         } else {
             try {
                 $newLocale = Zend_Locale::findLocale($locale);
             } catch (Zend_Locale_Exception $e) {
                 $this->_redirect();
             }
             $this->_setLocale($newLocale);
             setcookie('openskos_locale', $locale, time() + 60 * 60 * 24 * 30, '/');
             $this->_redirect();
         }
     } elseif (isset($_COOKIE['openskos_locale']) && ($locale = $_COOKIE['openskos_locale'])) {
         try {
             $newLocale = Zend_Locale::findLocale($locale);
         } catch (Zend_Locale_Exception $e) {
             setcookie('openskos_locale', '', time() - 3600, '/');
             return;
         }
         $this->_setLocale($newLocale);
     }
 }
示例#2
0
 public function _initTranslate()
 {
     $locale = new Zend_Locale(Zend_Locale::findLocale());
     $localeName = $locale->getLanguage();
     if (!in_array($localeName, array('en', 'ru'))) {
         $localeName = 'en';
     }
     $translate = new Zend_Translate(array('adapter' => 'tmx', 'content' => APPLICATION_PATH . '/configs/lang.xml', 'locale' => $localeName));
     Zend_Registry::set('Zend_Translate', $translate);
 }
 public function trlStaticExecute($language = null)
 {
     parent::trlStaticExecute($language);
     $locale = Kwf_Trl::getInstance()->trlcKwf('locale', 'C', array(), $language);
     if ($locale == 'C') {
         $locale = 'en_US';
     }
     $l = Zend_Locale::findLocale($locale);
     $this->_floatValidator->setLocale($l);
 }
示例#4
0
文件: Facebook.php 项目: robeendey/ce
 /**
  * Generates the button used for Facebook Connect
  *
  * @param mixed $fb_params A string or array of Facebook parameters for login
  * @param string $connect_with_facebook The string to display inside the button
  * @return String Generates HTML code for facebook login button
  */
 public static function loginButton($connect_with_facebook = 'Connect with Facebook', $prevent_reload = false)
 {
     $settings = Engine_Api::_()->getApi('settings', 'core');
     $facebook = self::getFBInstance();
     $fb_params = array('display' => 'page', 'req_perms' => array());
     switch ($settings->core_facebook_enable) {
         case 'login':
             break;
         case 'publish':
             $fb_params['req_perms'][] = 'email';
             $fb_params['req_perms'][] = 'user_birthday';
             $fb_params['req_perms'][] = 'user_status';
             $fb_params['req_perms'][] = 'publish_stream';
             break;
         case 'none':
         default:
             return;
     }
     $fb_params['req_perms'] = implode(',', $fb_params['req_perms']);
     $fb_href = $facebook->getLoginUrl($fb_params);
     $fb_onclick = "FB.login(null, {perms:'{$fb_params['req_perms']}'});return false;";
     return '
   <div id="fb-root"></div>
   <script type="text/javascript">
   //<![CDATA[
     (function(){
       var e = document.createElement("script");
           e.async = true;
           e.src = document.location.protocol + "//connect.facebook.net/' . Zend_Locale::findLocale() . '/all.js";
       document.getElementById("fb-root").appendChild(e);
     }());
     window.fbAsyncInit = function() {
       FB.init({
         appId: "' . $settings->core_facebook_appid . '",
         status: true,
         cookie: true,
         xfbml: true
       });
       FB.Event.subscribe(\'auth.sessionChange\', function(response) {
         ' . ($prevent_reload ? '' : 'if (-1 != document.cookie.search(/^(.*; ?)fbs_/)) window.location.reload();') . '
         }); };
       (function() {
         var e = document.createElement("script"); e.async = true; e.src = document.location.protocol + "//connect.facebook.net/' . Zend_Locale::findLocale() . '/all.js";
         document.getElementById("fb-root").appendChild(e);
       }());
   //]]>
   </script>
   <a href="' . $fb_href . '" target="_blank" onclick="' . $fb_onclick . '"><img src="http://static.ak.fbcdn.net/rsrc.php/z38X1/hash/6ad3z8m6.gif" border="0" alt="' . $connect_with_facebook . '" /></a>
   ';
 }
 public function localeAction()
 {
     $locale = $this->_getParam('locale');
     $language = $this->_getParam('language');
     $return = $this->_getParam('return', $this->_helper->url->url(array(), 'default', true));
     $viewer = Engine_Api::_()->user()->getViewer();
     if (!empty($locale)) {
         try {
             $locale = Zend_Locale::findLocale($locale);
         } catch (Exception $e) {
             $locale = null;
         }
     }
     if (!empty($language)) {
         try {
             $language = Zend_Locale::findLocale($language);
         } catch (Exception $e) {
             $language = null;
         }
     }
     if ($language && !$locale) {
         $locale = $language;
     }
     if (!$language && $locale) {
         $language = $locale;
     }
     if ($language && $locale) {
         // Set as cookie
         setcookie('en4_language', $language, time() + 86400 * 365, '/');
         setcookie('en4_locale', $locale, time() + 86400 * 365, '/');
         // Set as database
         if ($viewer && $viewer->getIdentity()) {
             $viewer->locale = $locale;
             $viewer->language = $language;
             $viewer->save();
         }
     }
     return $this->_helper->redirector->gotoUrl($return, array('prependBase' => false));
 }
示例#6
0
 /**
  * Internal function for adding translation data
  *
  * This may be a new language or additional data for an existing language
  * If the options 'clear' is true, then the translation data for the specified
  * language is replaced and added otherwise
  *
  * @see    Zend_Locale
  * @param  array|Zend_Config $content Translation data to add
  * @throws Zend_Translate_Exception
  * @return Zend_Translate_Adapter Provides fluent interface
  */
 private function _addTranslationData($options = array())
 {
     if ($options instanceof Zend_Config) {
         $options = $options->toArray();
     } else {
         if (func_num_args() > 1) {
             $args = func_get_args();
             $options['content'] = array_shift($args);
             if (!empty($args)) {
                 $options['locale'] = array_shift($args);
             }
             if (!empty($args)) {
                 $options += array_shift($args);
             }
         }
     }
     if ($options['content'] instanceof Zend_Translate || $options['content'] instanceof Zend_Translate_Adapter) {
         $options['usetranslateadapter'] = true;
         if (!empty($options['locale']) && $options['locale'] !== 'auto') {
             $options['content'] = $options['content']->getMessages($options['locale']);
         } else {
             $content = $options['content'];
             $locales = $content->getList();
             foreach ($locales as $locale) {
                 $options['locale'] = $locale;
                 $options['content'] = $content->getMessages($locale);
                 $this->_addTranslationData($options);
             }
             return $this;
         }
     }
     try {
         $options['locale'] = Zend_Locale::findLocale($options['locale']);
     } catch (Zend_Locale_Exception $e) {
         #require_once 'Zend/Translate/Exception.php';
         throw new Zend_Translate_Exception("The given Language '{$options['locale']}' does not exist", 0, $e);
     }
     if ($options['clear'] || !isset($this->_translate[$options['locale']])) {
         $this->_translate[$options['locale']] = array();
     }
     $read = true;
     if (isset(self::$_cache)) {
         $id = 'Zend_Translate_' . md5(serialize($options['content'])) . '_' . $this->toString();
         $temp = self::$_cache->load($id);
         if ($temp) {
             $read = false;
         }
     }
     if ($options['reload']) {
         $read = true;
     }
     if ($read) {
         if (!empty($options['usetranslateadapter'])) {
             $temp = array($options['locale'] => $options['content']);
         } else {
             $temp = $this->_loadTranslationData($options['content'], $options['locale'], $options);
         }
     }
     if (empty($temp)) {
         $temp = array();
     }
     $keys = array_keys($temp);
     foreach ($keys as $key) {
         if (!isset($this->_translate[$key])) {
             $this->_translate[$key] = array();
         }
         if (array_key_exists($key, $temp) && is_array($temp[$key])) {
             $this->_translate[$key] = $temp[$key] + $this->_translate[$key];
         }
     }
     if ($this->_automatic === true) {
         $find = new Zend_Locale($options['locale']);
         $browser = $find->getEnvironment() + $find->getBrowser();
         arsort($browser);
         foreach ($browser as $language => $quality) {
             if (isset($this->_translate[$language])) {
                 $this->_options['locale'] = $language;
                 break;
             }
         }
     }
     if ($read and isset(self::$_cache)) {
         $id = 'Zend_Translate_' . md5(serialize($options['content'])) . '_' . $this->toString();
         if (self::$_cacheTags) {
             self::$_cache->save($temp, $id, array($this->_options['tag']));
         } else {
             self::$_cache->save($temp, $id);
         }
     }
     return $this;
 }
示例#7
0
文件: Tmx.php 项目: netixx/Stock
 /**
  * Internal method, called by xml element handler at start
  *
  * @param resource $file   File handler
  * @param string   $name   Elements name
  * @param array    $attrib Attributes for this element
  */
 protected function _startElement($file, $name, $attrib)
 {
     if ($this->_seg !== null) {
         $this->_content .= "<" . $name;
         foreach ($attrib as $key => $value) {
             $this->_content .= " {$key}=\"{$value}\"";
         }
         $this->_content .= ">";
     } else {
         switch (strtolower($name)) {
             case 'header':
                 if (empty($this->_useId) && isset($attrib['srclang'])) {
                     if (Zend_Locale::isLocale($attrib['srclang'])) {
                         $this->_srclang = Zend_Locale::findLocale($attrib['srclang']);
                     } else {
                         if (!$this->_options['disableNotices']) {
                             if ($this->_options['log']) {
                                 $this->_options['log']->notice("The language '{$attrib['srclang']}' can not be set because it does not exist.");
                             } else {
                                 trigger_error("The language '{$attrib['srclang']}' can not be set because it does not exist.", E_USER_NOTICE);
                             }
                         }
                         $this->_srclang = $attrib['srclang'];
                     }
                 }
                 break;
             case 'tu':
                 if (isset($attrib['tuid'])) {
                     $this->_tu = $attrib['tuid'];
                 }
                 break;
             case 'tuv':
                 if (isset($attrib['xml:lang'])) {
                     if (Zend_Locale::isLocale($attrib['xml:lang'])) {
                         $this->_tuv = Zend_Locale::findLocale($attrib['xml:lang']);
                     } else {
                         if (!$this->_options['disableNotices']) {
                             if ($this->_options['log']) {
                                 $this->_options['log']->notice("The language '{$attrib['xml:lang']}' can not be set because it does not exist.");
                             } else {
                                 trigger_error("The language '{$attrib['xml:lang']}' can not be set because it does not exist.", E_USER_NOTICE);
                             }
                         }
                         $this->_tuv = $attrib['xml:lang'];
                     }
                     if (!isset($this->_data[$this->_tuv])) {
                         $this->_data[$this->_tuv] = array();
                     }
                 }
                 break;
             case 'seg':
                 $this->_seg = true;
                 $this->_content = null;
                 break;
             default:
                 break;
         }
     }
 }
示例#8
0
 /**
  * Sets the locale option
  *
  * @param  string|Zend_Locale $locale
  * @return Zend_Validate_Date provides a fluent interface
  */
 public function setLocale($locale = null)
 {
     $this->_locale = Zend_Locale::findLocale($locale);
     return $this;
 }
示例#9
0
 /**
  * Sets the locale to use
  *
  * @param string|Zend_Locale $locale
  * @throws Zend_Validate_Exception On unrecognised region
  * @throws Zend_Validate_Exception On not detected format
  * @return Zend_Validate_PostCode  Provides fluid interface
  */
 public function setLocale($locale = null)
 {
     #require_once 'Zend/Locale.php';
     $this->_locale = Zend_Locale::findLocale($locale);
     $locale = new Zend_Locale($this->_locale);
     $region = $locale->getRegion();
     if (empty($region)) {
         #require_once 'Zend/Validate/Exception.php';
         throw new Zend_Validate_Exception("Unable to detect a region for the locale '{$locale}'");
     }
     $format = Zend_Locale::getTranslation($locale->getRegion(), 'postaltoterritory', $this->_locale);
     if (empty($format)) {
         #require_once 'Zend/Validate/Exception.php';
         throw new Zend_Validate_Exception("Unable to detect a postcode format for the region '{$locale->getRegion()}'");
     }
     $this->setFormat($format);
     return $this;
 }
 public function editAction()
 {
     $this->view->locale = $locale = $this->_getParam('locale');
     $this->view->page = $page = $this->_getParam('page');
     $translate = Zend_Registry::get('Zend_Translate');
     try {
         if (!$locale || !Zend_Locale::findLocale($locale)) {
             throw new Exception('missing locale ' . $locale);
         }
     } catch (Exception $e) {
         return $this->_helper->redirector->gotoRoute(array('action' => 'index', 'controller' => 'language'), 'admin_default', true);
     }
     // Process filter form
     $this->view->filterForm = $filterForm = new Core_Form_Admin_Language_Filter();
     $filterForm->isValid($this->_getAllParams());
     $filterValues = $filterForm->getValues();
     extract($filterValues);
     // search, show
     // Make query
     $filterValues = array_filter($filterValues);
     $this->view->values = $filterValues;
     $this->view->query = empty($filterValues) ? '' : '?' . http_build_query($filterValues);
     // Assign basic locale info
     $this->view->localeObject = $localeObject = new Zend_Locale($locale);
     $this->view->locale = $locale = $localeObject->toString();
     // Get locale translation info
     $localeLanguage = $localeObject->getLanguage();
     $localeRegion = $localeObject->getRegion();
     $this->view->localeLanguageTranslation = $localeLanguageTranslation = Zend_Locale::getTranslation($localeLanguage, 'language', Zend_Registry::get('Locale'));
     $this->view->localeRegionTranslation = $localeRegionTranslation = Zend_Locale::getTranslation($localeRegion, 'territory', Zend_Registry::get('Locale'));
     $translate = Zend_Registry::get('Zend_Translate');
     if ($localeLanguageTranslation && $localeRegionTranslation) {
         $this->view->localeTranslation = $localeLanguageTranslation . ' ' . sprintf($translate->translate('(%s)'), $localeRegionTranslation) . ' ' . sprintf($translate->translate('[%s]'), $locale);
     } else {
         if ($localeLanguageTranslation) {
             $this->view->localeTranslation = $localeLanguageTranslation . ' ' . sprintf($translate->translate('[%s]'), $locale);
         } else {
             $this->view->localeTranslation = sprintf($translate->translate('[%s]'), $locale);
         }
     }
     // Query plural system for max and sample space
     $sample = array();
     $max = 0;
     for ($i = 0; $i <= 1000; $i++) {
         $form = Zend_Translate_Plural::getPlural($i, $locale);
         $max = max($max, $form);
         if (@count($sample[$form]) < 3) {
             $sample[$form][] = $i;
         }
     }
     $this->view->pluralFormCount = $max + 1;
     $this->view->pluralFormSample = $sample;
     // Get initial and default values
     $baseMessages = $translate->getMessages('en');
     if ($translate->isAvailable($locale)) {
         $currentMessages = $translate->getMessages($locale);
     } else {
         $currentMessages = array();
         // @todo this should redirect or smth
     }
     // Get phrases that are not in the english pack?
     if (!empty($currentMessages) && $locale != 'en') {
         $missingBasePhrases = array_diff_key($currentMessages, $baseMessages);
         $missingBasePhrases = array_combine(array_keys($missingBasePhrases), array_keys($missingBasePhrases));
         $baseMessages = array_merge($baseMessages, $missingBasePhrases);
     }
     // Build the fancy array
     $resultantMessages = array();
     $missing = 0;
     $index = 0;
     foreach ($baseMessages as $key => $value) {
         // Build
         $composite = array('uid' => ++$index, 'key' => $key, 'original' => $value, 'plural' => (bool) is_array($value));
         // filters, plurals, and missing, oh my.
         if (isset($currentMessages[$key])) {
             if ('missing' == $show) {
                 continue;
             }
             if (is_array($value) && !is_array($currentMessages[$key])) {
                 $composite['current'] = array($currentMessages[$key]);
             } else {
                 if (!is_array($value) && is_array($currentMessages[$key])) {
                     $composite['current'] = current($currentMessages[$key]);
                 } else {
                     $composite['current'] = $currentMessages[$key];
                 }
             }
         } else {
             if ('translated' == $show) {
                 continue;
             }
             if (is_array($value)) {
                 $composite['current'] = array();
             } else {
                 $composite['current'] = '';
             }
             $missing++;
         }
         // Do search
         if ($search && !$this->_searchArrayRecursive($search, $composite)) {
             continue;
         }
         // Add
         $resultantMessages[] = $composite;
     }
     // Build the paginator
     $this->view->paginator = $paginator = Zend_Paginator::factory($resultantMessages);
     $paginator->setItemCountPerPage(50);
     $paginator->setCurrentPageNumber($page);
     // Process form POST
     if ($this->getRequest()->isPost()) {
         $keys = $this->_getParam('keys');
         $values = $this->_getParam('values');
         // Try to combine the values and keys arrays
         $combined = array();
         foreach ($values as $index => $value) {
             if (is_string($value)) {
                 if (empty($value)) {
                     continue;
                 }
                 $key = $keys[$index];
                 $combined[$key] = $value;
             } else {
                 if (is_array($value)) {
                     if (empty($value) || array_filter($value) === array()) {
                         continue;
                     }
                     $key = $keys[$index][0];
                     $combined[$key] = $value;
                 }
             }
         }
         // Try to write to a file
         $targetFile = APPLICATION_PATH . '/application/languages/' . $locale . '/custom.csv';
         if (!file_exists($targetFile)) {
             touch($targetFile);
             chmod($targetFile, 0777);
         }
         $writer = new Engine_Translate_Writer_Csv($targetFile);
         $writer->setTranslations($combined);
         $writer->write();
         // flush cached language vars
         @Zend_Registry::get('Zend_Cache')->clean();
         // redirect to this same page to get the new values
         return $this->_redirect($_SERVER['REQUEST_URI'], array('prependBase' => false));
     }
 }
示例#11
0
文件: Log.php 项目: GemsTracker/MUtil
 public function getLogIndices()
 {
     $locale = null;
     if (\Zend_Registry::isRegistered('Zend_Locale')) {
         $locale = \Zend_Registry::get('Zend_Locale');
     } elseif (\Zend_Registry::isRegistered('locale')) {
         $locale = \Zend_Registry::get('locale');
     }
     if (!$locale instanceof \Zend_Locale) {
         $locale = \Zend_Locale::findLocale();
     }
     switch ($this->_logRotate) {
         case self::ROTATE_PER_MONTH:
             break;
     }
 }
示例#12
0
 public function preDispatch(\Zend_Controller_Request_Abstract $request)
 {
     $locale = new Zend_Locale(Zend_Locale::findLocale());
     $this->getResponse()->setHeader('Content-Language', $locale->getLanguage());
 }
示例#13
0
 /**
  * Internal function for adding translation data
  *
  * It may be a new language or additional data for existing language
  * If $clear parameter is true, then translation data for specified
  * language is replaced and added otherwise
  *
  * @see    Zend_Locale
  * @param  array|string       $data    Translation data
  * @param  string|Zend_Locale $locale  Locale/Language to add data for, identical with locale identifier,
  *                                     @see Zend_Locale for more information
  * @param  array              $options (optional) Option for this Adapter
  * @throws Zend_Translate_Exception
  * @return Zend_Translate_Adapter Provides fluent interface
  */
 private function _addTranslationData($data, $locale, array $options = array())
 {
     try {
         $locale = Zend_Locale::findLocale($locale);
     } catch (Zend_Locale_Exception $e) {
         require_once 'Zend/Translate/Exception.php';
         throw new Zend_Translate_Exception("The given Language '{$locale}' does not exist", 0, $e);
     }
     if ($options['clear'] || !isset($this->_translate[$locale])) {
         $this->_translate[$locale] = array();
     }
     $read = true;
     if (isset(self::$_cache)) {
         $id = 'Zend_Translate_' . md5(serialize($data)) . '_' . $this->toString();
         $temp = self::$_cache->load($id);
         if ($temp) {
             $read = false;
         }
     }
     if ($options['reload']) {
         $read = true;
     }
     if ($read) {
         $temp = $this->_loadTranslationData($data, $locale, $options);
     }
     if (empty($temp)) {
         $temp = array();
     }
     $keys = array_keys($temp);
     foreach ($keys as $key) {
         if (!isset($this->_translate[$key])) {
             $this->_translate[$key] = array();
         }
         if (array_key_exists($key, $temp) && is_array($temp[$key])) {
             $this->_translate[$key] = $temp[$key] + $this->_translate[$key];
         }
     }
     if ($this->_automatic === true) {
         $find = new Zend_Locale($locale);
         $browser = $find->getEnvironment() + $find->getBrowser();
         arsort($browser);
         foreach ($browser as $language => $quality) {
             if (isset($this->_translate[$language])) {
                 $this->_options['locale'] = $language;
                 break;
             }
         }
     }
     if ($read and isset(self::$_cache)) {
         $id = 'Zend_Translate_' . md5(serialize($data)) . '_' . $this->toString();
         self::$_cache->save($temp, $id, array('Zend_Translate'));
     }
     return $this;
 }
示例#14
0
 /**
  * Internal function for checking the options array of proper input values
  * See {@link setOptions()} for details.
  *
  * @param  array  $options  Array of options, keyed by option name: format_type = 'iso' | 'php', fix_date = true | false,
  *                          locale = Zend_Locale | locale string, precision = whole number between -1 and 30
  * @throws Zend_Locale_Exception
  * @return Options array if no option was given
  */
 private static function _checkOptions(array $options = array())
 {
     if (count($options) == 0) {
         return self::$_options;
     }
     foreach ($options as $name => $value) {
         $name = strtolower($name);
         if ($name !== 'locale') {
             if (gettype($value) === 'string') {
                 $value = strtolower($value);
             }
         }
         switch ($name) {
             case 'number_format':
                 if ($value == Zend_Locale_Format::STANDARD) {
                     $locale = self::$_options['locale'];
                     if (isset($options['locale'])) {
                         $locale = $options['locale'];
                     }
                     $options['number_format'] = Zend_Locale_Data::getContent($locale, 'decimalnumber');
                 } else {
                     if (gettype($value) !== 'string' and $value !== NULL) {
                         // require_once 'Zend/Locale/Exception.php';
                         throw new Zend_Locale_Exception("Unknown number format type '" . gettype($value) . "'. " . "Format '{$value}' must be a valid number format string.");
                     }
                 }
                 break;
             case 'date_format':
                 if ($value == Zend_Locale_Format::STANDARD) {
                     $locale = self::$_options['locale'];
                     if (isset($options['locale'])) {
                         $locale = $options['locale'];
                     }
                     $options['date_format'] = Zend_Locale_Format::getDateFormat($locale);
                 } else {
                     if (gettype($value) !== 'string' and $value !== NULL) {
                         // require_once 'Zend/Locale/Exception.php';
                         throw new Zend_Locale_Exception("Unknown dateformat type '" . gettype($value) . "'. " . "Format '{$value}' must be a valid ISO or PHP date format string.");
                     } else {
                         if (isset($options['format_type']) === true and $options['format_type'] == 'php' or isset($options['format_type']) === false and self::$_options['format_type'] == 'php') {
                             $options['date_format'] = Zend_Locale_Format::convertPhpToIsoFormat($value);
                         }
                     }
                 }
                 break;
             case 'format_type':
                 if ($value != 'php' && $value != 'iso') {
                     // require_once 'Zend/Locale/Exception.php';
                     throw new Zend_Locale_Exception("Unknown date format type '{$value}'. Only 'iso' and 'php'" . " are supported.");
                 }
                 break;
             case 'fix_date':
                 if ($value !== true && $value !== false) {
                     // require_once 'Zend/Locale/Exception.php';
                     throw new Zend_Locale_Exception("Enabling correction of dates must be either true or false" . "(fix_date='{$value}').");
                 }
                 break;
             case 'locale':
                 $options['locale'] = Zend_Locale::findLocale($value);
                 break;
             case 'cache':
                 if ($value instanceof Zend_Cache_Core) {
                     Zend_Locale_Data::setCache($value);
                 }
                 break;
             case 'disablecache':
                 Zend_Locale_Data::disableCache($value);
                 break;
             case 'precision':
                 if ($value === NULL) {
                     $value = -1;
                 }
                 if ($value < -1 || $value > 30) {
                     // require_once 'Zend/Locale/Exception.php';
                     throw new Zend_Locale_Exception("'{$value}' precision is not a whole number less than 30.");
                 }
                 break;
             default:
                 // require_once 'Zend/Locale/Exception.php';
                 throw new Zend_Locale_Exception("Unknown option: '{$name}' = '{$value}'");
                 break;
         }
     }
     return $options;
 }
示例#15
0
 protected function initTranslation(\Zend_Form $form, $id, $locale = null)
 {
     if ($locale === null) {
         $locale = \Zend_Locale::findLocale();
     }
     $trans = $this->translateForm($id, $locale);
     if ($locale != null && $locale != "") {
         if (null === $form->getTranslator()) {
             $form->setTranslator($trans);
         } else {
             $form->getTranslator()->addTranslation($trans);
         }
     }
 }
示例#16
0
 /**
  * Sets a new locale for data retreivement
  * Example: 'de_XX' will be set to 'de' because 'de_XX' does not exist
  * 'xx_YY' will be set to 'root' because 'xx' does not exist
  *
  * @param  string|Zend_Locale $locale (Optional) Locale for parsing input
  * @throws Zend_Currency_Exception When the given locale does not exist
  * @return Zend_Currency Provides fluent interface
  */
 public function setLocale($locale = null)
 {
     require_once 'Zend/Locale.php';
     try {
         $this->_locale = Zend_Locale::findLocale($locale);
     } catch (Zend_Locale_Exception $e) {
         require_once 'Zend/Currency/Exception.php';
         throw new Zend_Currency_Exception($e->getMessage());
     }
     // Get currency details
     $this->_options['currency'] = $this->getShortName(null, $this->_locale);
     $this->_options['name'] = $this->getName(null, $this->_locale);
     $this->_options['symbol'] = $this->getSymbol(null, $this->_locale);
     return $this;
 }
示例#17
0
 protected function _initLocale()
 {
     // Translate needs to be initialized before Modules, so _initTranslate() could
     // not load the "User" couldn't be initialized then.  Thus, we must assign
     // the language over here if it is a user.
     // Try to pull from various sources
     $timezone = 'Asia/Saigon';
     if (!empty($_COOKIE['en4_language']) && !empty($_COOKIE['en4_locale'])) {
         $locale = $_COOKIE['en4_locale'];
         $language = $_COOKIE['en4_language'];
     } else {
         $locale = 'vi_VN';
         $language = 'vi_VN';
     }
     Zend_Registry::set('timezone', $timezone);
     // Make sure it's valid
     try {
         $locale = Zend_Locale::findLocale($locale);
     } catch (Exception $e) {
         $locale = 'vi_VN';
     }
     try {
         $language = Zend_Locale::findLocale($language);
     } catch (Exception $e) {
         $language = 'vi_VN';
     }
     // Set in locale and language
     $this->getContainer()->translate->setLocale($language);
     $localeObject = new Zend_Locale($locale);
     Zend_Registry::set('Locale', $localeObject);
     // Set in locale and language
     $translate = $this->getContainer()->translate;
     $defaultLanguage = 'vi_VN';
     $selectedLanguage = $localeObject->getLanguage();
     if ($selectedLocale = $localeObject->getRegion()) {
         $selectedLanguage .= "_{$selectedLocale}";
     }
     if (!$translate->isAvailable($selectedLanguage)) {
         if (!$translate->isAvailable($defaultLanguage)) {
             $translate->setLocale('en_US');
         } else {
             $translate->setLocale($defaultLanguage);
         }
     } else {
         $translate->setLocale($language);
     }
     // Get orientation
     $localeData = Zend_Locale_Data::getList($localeObject->__toString(), 'layout');
     $this->getContainer()->layout->orientation = $localeData['characters'];
     return $localeObject;
 }
示例#18
0
 protected function _initLocale()
 {
     // Translate needs to be initialized before Modules, so _initTranslate() could
     // not load the "User" couldn't be initialized then.  Thus, we must assign
     // the language over here if it is a user.
     // Try to pull from various sources
     $viewer = Engine_Api::_()->user()->getViewer();
     $timezone = Engine_Api::_()->getApi('settings', 'core')->core_locale_timezone;
     if ($viewer->getIdentity()) {
         $locale = $viewer->locale;
         $language = $viewer->language;
         $timezone = $viewer->timezone;
     } else {
         if (!empty($_COOKIE['en4_language']) && !empty($_COOKIE['en4_locale'])) {
             $locale = $_COOKIE['en4_locale'];
             $language = $_COOKIE['en4_language'];
         } else {
             if (!empty($_SERVER["HTTP_ACCEPT_LANGUAGE"])) {
                 $l = new Zend_Locale(Zend_Locale::BROWSER);
                 $locale = $l->toString();
                 $language = $l->getLanguage();
             } else {
                 $locale = Engine_Api::_()->getApi('settings', 'core')->getSetting('core.locale.locale', 'auto');
                 $language = Engine_Api::_()->getApi('settings', 'core')->getSetting('core.locale.locale', 'auto');
             }
         }
     }
     Zend_Registry::set('timezone', $timezone);
     // Make sure it's valid
     try {
         $locale = Zend_Locale::findLocale($locale);
     } catch (Exception $e) {
         $locale = 'en_US';
     }
     $localeObject = new Zend_Locale($locale);
     Zend_Registry::set('Locale', $localeObject);
     // Set in locale and language
     $translate = $this->getContainer()->translate;
     $defaultLanguage = Engine_Api::_()->getApi('settings', 'core')->core_locale_locale;
     $localeLanguage = $localeObject->getLanguage();
     $ls = array($locale, $language, $localeLanguage, $defaultLanguage, 'en');
     foreach ($ls as $l) {
         if ($translate->isAvailable($l)) {
             $translate->setLocale($l);
             break;
         }
     }
     if (!$viewer->getIdentity()) {
         if (empty($_COOKIE['en4_language'])) {
             setcookie('en4_language', $translate->getLocale(), time() + 86400 * 365, '/');
         }
         if (empty($_COOKIE['en4_locale'])) {
             setcookie('en4_locale', $locale, time() + 86400 * 365, '/');
         }
     }
     // Set cache
     Zend_Locale_Data::setCache($this->getContainer()->cache);
     // Get orientation
     $localeData = Zend_Locale_Data::getList($localeObject->__toString(), 'layout');
     $this->getContainer()->layout->orientation = $localeData['characters'];
     return $localeObject;
 }
示例#19
0
 public function addTranslation($data, $locale = null, array $options = array())
 {
     $this->setOptions($options);
     $originate = (string) $locale;
     if (array_key_exists('locale', $options)) {
         if ($locale == null) {
             $locale = $options['locale'];
         }
         unset($options['locale']);
     }
     if (array_key_exists('log', $options) && !$options['log'] instanceof Zend_Log) {
         require_once 'Zend/Translate/Exception.php';
         throw new Zend_Translate_Exception('Instance of Zend_Log expected for option log');
     }
     try {
         $locale = Zend_Locale::findLocale($locale);
     } catch (Zend_Locale_Exception $e) {
         require_once 'Zend/Translate/Exception.php';
         throw new Zend_Translate_Exception("The given Language '{$locale}' does not exist");
     }
     if (is_string($data) and is_dir($data)) {
         $data = realpath($data);
         $prev = '';
         foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($data, RecursiveDirectoryIterator::KEY_AS_PATHNAME), RecursiveIteratorIterator::SELF_FIRST) as $directory => $info) {
             $file = $info->getFilename();
             if (strpos($directory, DIRECTORY_SEPARATOR . $options['ignore']) !== false) {
                 // ignore files matching first characters from option 'ignore' and all files below
                 continue;
             }
             if ($info->isDir()) {
                 // pathname as locale
                 if ($options['scan'] === self::LOCALE_DIRECTORY and Zend_Locale::isLocale($file, true, false)) {
                     $locale = $file;
                     $prev = (string) $locale;
                 }
             } else {
                 if ($info->isFile()) {
                     // filename as locale
                     if ($options['scan'] === self::LOCALE_FILENAME) {
                         $filename = explode('.', $file);
                         array_pop($filename);
                         $filename = implode('.', $filename);
                         if (Zend_Locale::isLocale((string) $filename, true, false)) {
                             $locale = (string) $filename;
                         } else {
                             $parts = explode('.', $file);
                             $parts2 = array();
                             foreach ($parts as $token) {
                                 $parts2 += explode('_', $token);
                             }
                             $parts = array_merge($parts, $parts2);
                             $parts2 = array();
                             foreach ($parts as $token) {
                                 $parts2 += explode('-', $token);
                             }
                             $parts = array_merge($parts, $parts2);
                             $parts = array_unique($parts);
                             $prev = '';
                             foreach ($parts as $token) {
                                 if (Zend_Locale::isLocale($token, true, false)) {
                                     if (strlen($prev) <= strlen($token)) {
                                         $locale = $token;
                                         $prev = $token;
                                     }
                                 }
                             }
                         }
                     }
                     try {
                         $this->_addTranslationData($info->getPathname(), (string) $locale, $options);
                     } catch (Zend_Translate_Exception $e) {
                         // ignore failed sources while scanning
                     }
                 }
             }
         }
     } else {
         $this->_addTranslationData($data, (string) $locale, $options);
     }
     if (isset($this->_translate[$originate]) === true and count($this->_translate[$originate]) > 0) {
         $this->setLocale($originate);
     }
     return $this;
 }
示例#20
0
 /**
  * Internal function for adding translation data
  *
  * It may be a new language or additional data for existing language
  * If $clear parameter is true, then translation data for specified
  * language is replaced and added otherwise
  *
  * @see    Zend_Locale
  * @param  array|string       $data    Translation data
  * @param  string|Zend_Locale $locale  Locale/Language to add data for, identical with locale identifier,
  *                                     @see Zend_Locale for more information
  * @param  array              $options (optional) Option for this Adapter
  * @throws Zend_Translate_Exception
  * @return Zend_Translate_Adapter Provides fluent interface
  */
 private function _addTranslationData($data, $locale, array $options = array())
 {
     try {
         $locale = Zend_Locale::findLocale($locale);
     } catch (Zend_Locale_Exception $e) {
         require_once 'Zend/Translate/Exception.php';
         throw new Zend_Translate_Exception("The given Language '{$locale}' does not exist");
     }
     if (isset($this->_translate[$locale]) === false) {
         $this->_translate[$locale] = array();
     }
     $read = true;
     if (isset(self::$_cache)) {
         $id = 'Zend_Translate_' . preg_replace('/[^a-zA-Z0-9_]/', '_', $data) . '_' . $locale . '_' . $this->toString();
         $result = self::$_cache->load($id);
         if ($result) {
             $this->_translate[$locale] = unserialize($result);
             $read = false;
         }
     }
     if ($read) {
         $this->_loadTranslationData($data, $locale, $options);
     }
     if ($this->_automatic === true) {
         $find = new Zend_Locale($locale);
         $browser = $find->getEnvironment() + $find->getBrowser();
         arsort($browser);
         foreach ($browser as $language => $quality) {
             if (isset($this->_translate[$language]) === true) {
                 $this->_options['locale'] = $language;
                 break;
             }
         }
     }
     if ($read and isset(self::$_cache)) {
         $id = 'Zend_Translate_' . preg_replace('/[^a-zA-Z0-9_]/', '_', $data) . '_' . $locale . '_' . $this->toString();
         self::$_cache->save(serialize($this->_translate[$locale]), $id);
     }
     return $this;
 }
示例#21
0
 /**
  * Sets locale.
  * @param string $locale
  */
 public function setLocale($locale)
 {
     if (is_string($locale)) {
         try {
             $this->_locale = Zend_Locale::findLocale($locale);
         } catch (Zend_Locale_Exception $e) {
             App::log()->WARN("Locale '{$locale}' not found. Using default locale (en).");
         }
     }
     return $this;
 }
示例#22
0
文件: Iban.php 项目: kokx/zf-library
 /**
  * Sets the locale option
  *
  * @param  string|Zend_Locale $locale
  * @return Zend_Validate_Date provides a fluent interface
  */
 public function setLocale($locale = null)
 {
     if ($locale !== false) {
         require_once 'Zend/Locale.php';
         $locale = Zend_Locale::findLocale($locale);
         if (strlen($locale) < 4) {
             require_once 'Zend/Validate/Exception.php';
             throw new Zend_Validate_Exception('Region must be given for IBAN validation');
         }
     }
     $this->_locale = $locale;
     return $this;
 }
示例#23
0
 public static function getLocale()
 {
     return Zend_Locale::findLocale(self::$locale);
 }
 /**
  * Checks if the given date is a real date or datepart.
  * Returns false if a expected datepart is missing or a datepart exceeds its possible border.
  * But the check will only be done for the expected dateparts which are given by format.
  * If no format is given the standard dateformat for the actual locale is used.
  * f.e. 30.February.2007 will return false if format is 'dd.MMMM.YYYY'
  *
  * @param  string|array|Zend_Date $date   Date to parse for correctness
  * @param  string                 $format (Optional) Format for parsing the date string
  * @param  string|Zend_Locale     $locale (Optional) Locale for parsing date parts
  * @return boolean                True when all date parts are correct
  */
 public static function isDate($date, $format = null, $locale = null)
 {
     if (!is_string($date) && !is_numeric($date) && !$date instanceof Zend_Date && !is_array($date)) {
         return false;
     }
     if ($format !== null && $format != 'ee' && $format != 'ss' && $format != 'GG' && $format != 'MM' && $format != 'EE' && $format != 'TT' && Zend_Locale::isLocale($format, null, false)) {
         $locale = $format;
         $format = null;
     }
     $locale = Zend_Locale::findLocale($locale);
     if ($format === null) {
         $format = Zend_Locale_Format::getDateFormat($locale);
     } else {
         if (self::$_options['format_type'] == 'php' && !defined($format)) {
             $format = Zend_Locale_Format::convertPhpToIsoFormat($format);
         }
     }
     $format = self::_getLocalizedToken($format, $locale);
     if (!is_array($date)) {
         try {
             $parsed = Zend_Locale_Format::getDate($date, array('locale' => $locale, 'date_format' => $format, 'format_type' => 'iso', 'fix_date' => false));
         } catch (Zend_Locale_Exception $e) {
             // Date can not be parsed
             return false;
         }
     } else {
         $parsed = $date;
     }
     if ((strpos($format, 'Y') !== false or strpos($format, 'y') !== false) and !isset($parsed['year'])) {
         // Year expected but not found
         return false;
     }
     if (strpos($format, 'M') !== false and !isset($parsed['month'])) {
         // Month expected but not found
         return false;
     }
     if (strpos($format, 'd') !== false and !isset($parsed['day'])) {
         // Day expected but not found
         return false;
     }
     if ((strpos($format, 'H') !== false or strpos($format, 'h') !== false) and !isset($parsed['hour'])) {
         // Hour expected but not found
         return false;
     }
     if (strpos($format, 'm') !== false and !isset($parsed['minute'])) {
         // Minute expected but not found
         return false;
     }
     if (strpos($format, 's') !== false and !isset($parsed['second'])) {
         // Second expected  but not found
         return false;
     }
     // Set not given dateparts
     if (isset($parsed['hour']) === false) {
         $parsed['hour'] = 12;
     }
     if (isset($parsed['minute']) === false) {
         $parsed['minute'] = 0;
     }
     if (isset($parsed['second']) === false) {
         $parsed['second'] = 0;
     }
     if (isset($parsed['month']) === false) {
         $parsed['month'] = 1;
     }
     if (isset($parsed['day']) === false) {
         $parsed['day'] = 1;
     }
     if (isset($parsed['year']) === false) {
         $parsed['year'] = 1970;
     }
     if (self::isYearLeapYear($parsed['year'])) {
         $parsed['year'] = 1972;
     } else {
         $parsed['year'] = 1971;
     }
     $date = new self($parsed, null, $locale);
     $timestamp = $date->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $parsed['month'], $parsed['day'], $parsed['year']);
     if ($parsed['year'] != $date->date('Y', $timestamp)) {
         // Given year differs from parsed year
         return false;
     }
     if ($parsed['month'] != $date->date('n', $timestamp)) {
         // Given month differs from parsed month
         return false;
     }
     if ($parsed['day'] != $date->date('j', $timestamp)) {
         // Given day differs from parsed day
         return false;
     }
     if ($parsed['hour'] != $date->date('G', $timestamp)) {
         // Given hour differs from parsed hour
         return false;
     }
     if ($parsed['minute'] != $date->date('i', $timestamp)) {
         // Given minute differs from parsed minute
         return false;
     }
     if ($parsed['second'] != $date->date('s', $timestamp)) {
         // Given second differs from parsed second
         return false;
     }
     return true;
 }
示例#25
0
文件: Tool.php 项目: krugerke/pimcore
 /**
  * @return array|mixed
  * @throws \Zend_Locale_Exception
  */
 public static function getSupportedLocales()
 {
     // List of locales that are no longer part of CLDR
     // this was also changed in the Zend Framework, but here we need to provide an appropriate alternative
     // since this information isn't public in \Zend_Locale :-(
     $aliases = ['az_AZ' => true, 'bs_BA' => true, 'ha_GH' => true, 'ha_NE' => true, 'ha_NG' => true, 'kk_KZ' => true, 'ks_IN' => true, 'mn_MN' => true, 'ms_BN' => true, 'ms_MY' => true, 'ms_SG' => true, 'pa_IN' => true, 'pa_PK' => true, 'shi_MA' => true, 'sr_BA' => true, 'sr_ME' => true, 'sr_RS' => true, 'sr_XK' => true, 'tg_TJ' => true, 'tzm_MA' => true, 'uz_AF' => true, 'uz_UZ' => true, 'vai_LR' => true, 'zh_CN' => true, 'zh_HK' => true, 'zh_MO' => true, 'zh_SG' => true, 'zh_TW' => true];
     $locale = \Zend_Locale::findLocale();
     $cacheKey = "system_supported_locales_" . strtolower((string) $locale);
     if (!($languageOptions = Cache::load($cacheKey))) {
         // we use the locale here, because \Zend_Translate only supports locales not "languages"
         $languages = \Zend_Locale::getLocaleList();
         $languages = array_merge($languages, $aliases);
         $languageOptions = array();
         foreach ($languages as $code => $active) {
             if ($active) {
                 $translation = \Zend_Locale::getTranslation($code, "language");
                 if (!$translation) {
                     $tmpLocale = new \Zend_Locale($code);
                     $lt = \Zend_Locale::getTranslation($tmpLocale->getLanguage(), "language");
                     $tt = \Zend_Locale::getTranslation($tmpLocale->getRegion(), "territory");
                     if ($lt && $tt) {
                         $translation = $lt . " (" . $tt . ")";
                     }
                 }
                 if (!$translation) {
                     $translation = $code;
                 }
                 $languageOptions[$code] = $translation;
             }
         }
         asort($languageOptions);
         Cache::save($languageOptions, $cacheKey, ["system"]);
     }
     return $languageOptions;
 }
示例#26
0
文件: Int.php 项目: bizanto/Hooked
 /**
  * Sets the locale to use
  *
  * @param string|Zend_Locale $locale
  */
 public function setLocale($locale = null)
 {
     require_once 'Zend/Locale.php';
     $this->_locale = Zend_Locale::findLocale($locale);
     return $this;
 }
示例#27
0
 /**
  * test MultiPartLocales
  * expected boolean
  */
 public function testLongLocale()
 {
     $locale = new Zend_LocaleTestHelper('de_Latn_DE');
     $this->assertEquals('de_DE', $locale->toString());
     $this->assertTrue(Zend_LocaleTestHelper::isLocale('de_Latn_CAR_DE_sup3_win'));
     $locale = new Zend_LocaleTestHelper('de_Latn_DE');
     $this->assertEquals('de_DE', $locale->toString());
     $this->assertEquals('fr_FR', Zend_Locale::findLocale('fr-Arab-FR'));
 }
示例#28
0
 /**
  * Sets a new locale for data retreivement
  * Example: 'de_XX' will be set to 'de' because 'de_XX' does not exist
  * 'xx_YY' will be set to 'root' because 'xx' does not exist
  *
  * @param  string|Zend_Locale $locale (Optional) Locale for parsing input
  * @throws Zend_Currency_Exception When the given locale does not exist
  * @return Zend_Currency Provides fluent interface
  */
 public function setLocale($locale = null)
 {
     require_once 'Zend/Locale.php';
     try {
         $locale = Zend_Locale::findLocale($locale);
         if (strlen($locale) > 4) {
             $this->_options['locale'] = $locale;
         } else {
             require_once 'Zend/Currency/Exception.php';
             throw new Zend_Currency_Exception("No region found within the locale '" . (string) $locale . "'");
         }
     } catch (Zend_Locale_Exception $e) {
         require_once 'Zend/Currency/Exception.php';
         throw new Zend_Currency_Exception($e->getMessage());
     }
     // Get currency details
     $this->_options['currency'] = $this->getShortName(null, $this->_options['locale']);
     $this->_options['name'] = $this->getName(null, $this->_options['locale']);
     $this->_options['symbol'] = $this->getSymbol(null, $this->_options['locale']);
     return $this;
 }
示例#29
0
 /**
  * @ZF-9488
  */
 public function testTerritoryToGetLocale()
 {
     $value = Zend_Locale::findLocale('US');
     $this->assertEquals('en_US', $value);
     $value = new Zend_Locale('US');
     $this->assertEquals('en_US', $value->toString());
     $value = new Zend_Locale('TR');
     $this->assertEquals('tr_TR', $value->toString());
 }