/**
  * Hook that loads the form data from $_POST or the model
  *
  * Or from whatever other source you specify here.
  */
 protected function loadFormData()
 {
     parent::loadFormData();
     $surveyId = $this->request->getParam(\MUtil_Model::REQUEST_ID);
     if (isset($this->formData['survey']) && $this->formData['survey'] && !$this->_survey instanceof \Gems_Tracker_Survey) {
         $this->_survey = $this->loader->getTracker()->getSurvey($this->formData['survey']);
     }
     if ($this->_survey instanceof \Gems_Tracker_Survey) {
         // Add (optional) survey specific translators
         $extraTrans = $this->importLoader->getAnswerImporters($this->_survey);
         if ($extraTrans) {
             $this->importTranslators = $extraTrans + $this->importTranslators;
             $this->_translatorDescriptions = false;
             $this->importModel->set('trans', 'multiOptions', $this->getTranslatorDescriptions());
         }
     }
     if ($this->_survey instanceof \Gems_Tracker_Survey) {
         $this->targetModel = $this->_survey->getAnswerModel($this->locale->toString());
         $this->importer->setTargetModel($this->targetModel);
         $source = $this->menu->getParameterSource();
         $source->offsetSet('gsu_has_pdf', $this->_survey->hasPdf() ? 1 : 0);
         $source->offsetSet('gsu_active', $this->_survey->isActive() ? 1 : 0);
     }
     // \MUtil_Echo::track($this->formData);
 }
Exemplo n.º 2
0
    public function testDefaultLocale()
    {
        $lang = new Zend_Translate(Zend_Translate::AN_ARRAY, array());

        $defaultLocale = new Zend_Locale();
        $this->assertEquals($lang->getLocale(), $defaultLocale->toString());
    }
Exemplo n.º 3
0
 /**
  * Get last locale, used before last emulation
  *
  */
 public function revert()
 {
     if ($locale = array_pop($this->_emulatedLocales)) {
         $this->_locale = $locale;
         $this->_localeCode = $this->_locale->toString();
         Mage::getSingleton('core/translate')->setLocale($this->_locale)->init('adminhtml', true);
     }
 }
Exemplo n.º 4
0
 private function resolveLocale(\Zend_Locale $locale)
 {
     $proposed = array($locale->toString(), $locale->getLanguage(), self::DEFAULT_LANG);
     foreach ($proposed as $lang) {
         if (isset(self::$trans[$lang])) {
             return $lang;
         }
     }
 }
Exemplo n.º 5
0
 /**
  * This function returns the rating link for Trusted Shops.
  *
  * @param $tsID
  * @return string
  */
 private function getRatingLink($tsID)
 {
     $isoCode = $this->locale->toString();
     switch ($isoCode) {
         case 'de_DE':
             return 'https://www.trustedshops.de/bewertung/info_' . $tsID . '.html';
         case 'de_AT':
             return 'https://www.trustedshops.at/bewertung/info_' . $tsID . '.html';
         case 'de_CH':
             return 'https://www.trustedshops.ch/bewertung/info_' . $tsID . '.html';
         case 'fr_FR':
             return 'https://www.trustedshops.fr/evaluation/info_' . $tsID . '.html';
         case 'es_ES':
             return 'https://www.trustedshops.es/evaluacion/info_' . $tsID . '.html';
         case 'pl_PL':
             return 'https://www.trustedshops.pl/opinia/info_' . $tsID . '.html';
         default:
             return 'https://www.trustedshops.com/buyerrating/info_' . $tsID . '.html';
     }
 }
Exemplo n.º 6
0
 public function confirmaremailAction()
 {
     self::requireIsPost();
     $code = trim($this->getRequest()->getParam('twucode'));
     if (!$_SESSION['twc']) {
         echo json_encode(array('status' => 0, 'msg' => _("Perdemos seu cadastro, volte e tente novamente.")));
         die;
     }
     if (strlen($code) != 6 || strtoupper($code) != $_SESSION['twc']['code']) {
         echo json_encode(array('status' => 0, 'msg' => _("O código não condiz com o que foi enviado por e-mail.")));
     } else {
         $locale = new Zend_Locale();
         Model_Usuario::getInstance()->cadastrar(array('locale' => $locale->toString(), 'nu_usuario' => uniqid(""), 'no_usuario' => $_SESSION['twc']['nome'], 'no_email' => $_SESSION['twc']['email'], 'tx_senha' => $_SESSION['twc']['senha']));
         $mailcontent = $this->view->partial('helpers/mail_novocadastro.phtml', $param);
         $mailcontent = $this->view->partial('helpers/mail_layout.phtml', array('title' => _("Trash Of WEB - Seja bem vindo!"), 'content' => $mailcontent));
         General::mail(array("email" => $_SESSION['twc']['email'], "title" => _("Trash Of WEB - Seja bem vindo!"), "content" => $mailcontent));
         General::login(array('no_email' => $_SESSION['twc']['email'], 'tx_senha' => $_SESSION['twc']['senha']));
         unset($_SESSION['twc']);
         echo json_encode(array('status' => 1, 'msg' => NULL));
     }
 }
Exemplo n.º 7
0
 /**
  * Returns a list of available translation languages
  * @param $detailed boolean Fetch additional info for translation
  * @return array List of translations
  */
 public function getLanguages($detailed = true)
 {
     $websiteConfigHelper = Zend_Controller_Action_HelperBroker::getExistingHelper('website');
     $languageIcons = Tools_Filesystem_Tools::findFilesByExtension($websiteConfigHelper->getPath() . $this->_langFlagsDir, 'png', false, true, false);
     $this->_languages = array();
     $loadedList = Zend_Registry::get('Zend_Translate')->getAdapter()->getList();
     foreach ($languageIcons as $country => $imgFile) {
         $locale = new Zend_Locale(Zend_Locale::getLocaleToTerritory($country));
         $lang = $locale->getLanguage();
         $langTitle = Zend_Locale::getTranslation($lang, 'language');
         if (!in_array($locale->getLanguage(), $loadedList)) {
             continue;
         }
         if ($detailed) {
             $this->_languages[$country] = array('locale' => $locale->toString(), 'language' => $langTitle, 'name' => $country, 'flag' => $this->_langFlagsDir . $imgFile);
         } else {
             $this->_languages[$country] = $langTitle;
         }
         unset($locale);
     }
     return $this->_languages;
 }
Exemplo n.º 8
0
 /**
  * test setOption
  * expected boolean
  */
 public function testSetOption()
 {
     $this->assertEquals(8, count(Zend_Locale_Format::setOptions(array('format_type' => 'php'))));
     $this->assertTrue(is_array(Zend_Locale_Format::setOptions()));
     try {
         $this->assertTrue(Zend_Locale_Format::setOptions(array('format_type' => 'xxx')));
         $this->fail("exception expected");
     } catch (Zend_Locale_Exception $e) {
         // success
     }
     try {
         $this->assertTrue(Zend_Locale_Format::setOptions(array('myformat' => 'xxx')));
         $this->fail("exception expected");
     } catch (Zend_Locale_Exception $e) {
         // success
     }
     $format = Zend_Locale_Format::setOptions(array('locale' => 'de', 'number_format' => Zend_Locale_FORMAT::STANDARD));
     $test = Zend_Locale_Data::getContent('de', 'decimalnumber');
     $this->assertEquals($test, $format['number_format']);
     try {
         $this->assertFalse(Zend_Locale_Format::setOptions(array('number_format' => array('x' => 'x'))));
         $this->fail("exception expected");
     } catch (Zend_Locale_Exception $e) {
         // success
     }
     $format = Zend_Locale_Format::setOptions(array('locale' => 'de', 'date_format' => Zend_Locale_Format::STANDARD));
     $test = Zend_Locale_Format::getDateFormat('de');
     $this->assertEquals($test, $format['date_format']);
     try {
         $this->assertFalse(Zend_Locale_Format::setOptions(array('date_format' => array('x' => 'x'))));
         $this->fail("exception expected");
     } catch (Zend_Locale_Exception $e) {
         // success
     }
     try {
         $this->assertFalse(is_array(Zend_Locale_Format::setOptions(array('fix_date' => 'no'))));
         $this->fail("exception expected");
     } catch (Zend_Locale_Exception $e) {
         // success
     }
     $format = Zend_Locale_Format::setOptions(array('locale' => Zend_Locale_Format::STANDARD));
     $locale = new Zend_Locale();
     $this->assertEquals($locale->toString(), $format['locale']);
     try {
         $this->assertFalse(is_array(Zend_Locale_Format::setOptions(array('locale' => 'nolocale'))));
         $this->fail("exception expected");
     } catch (Zend_Locale_Exception $e) {
         // success
     }
     try {
         $this->assertFalse(is_array(Zend_Locale_Format::setOptions(array('precision' => 50))));
         $this->fail("exception expected");
     } catch (Zend_Locale_Exception $e) {
         // success
     }
     // test interaction between class-wide default date format and using locale's default format
     try {
         $result = array('date_format' => 'MMM d, y', 'locale' => 'en_US', 'month' => '7', 'day' => '4', 'year' => '2007');
         Zend_Locale_Format::setOptions(array('format_type' => 'iso', 'date_format' => 'MMM d, y', 'locale' => 'en_US'));
         // test setUp
     } catch (Zend_Locale_Exception $e) {
         $this->fail("exception expected");
     }
     try {
         // uses global date_format with global locale
         $this->assertSame($result, Zend_Locale_Format::getDate('July 4, 2007'));
     } catch (Zend_Locale_Exception $e) {
         $this->fail("exception expected");
     }
     try {
         // uses global date_format with given locale
         $this->assertSame($result, Zend_Locale_Format::getDate('July 4, 2007', array('locale' => 'en_US')));
     } catch (Zend_Locale_Exception $e) {
         $this->fail("exception expected");
     }
     try {
         // sets a new global date format
         Zend_Locale_Format::setOptions(array('date_format' => 'M-d-y'));
     } catch (Zend_Locale_Exception $e) {
         $this->fail("exception expected");
     }
     try {
         // uses global date format with given locale
         // but this date format differs from the original set... (MMMM d, yyyy != M-d-y)
         $expected = Zend_Locale_Format::getDate('July 4, 2007', array('locale' => 'en_US'));
         $this->assertSame($expected['year'], $result['year']);
         $this->assertSame($expected['month'], $result['month']);
         $this->assertSame($expected['day'], $result['day']);
     } catch (Zend_Locale_Exception $e) {
         $this->fail("exception expected");
     }
     try {
         // the following should not be used... instead of null, Zend_Locale::ZFDEFAULT should be used
         // uses given local with standard format from this locale
         $this->assertSame($result, Zend_Locale_Format::getDate('July 4, 2007', array('locale' => 'en_US', 'date_format' => null)));
     } catch (Zend_Locale_Exception $e) {
         $this->fail("exception expected");
     }
     try {
         // uses given locale with standard format from this locale
         $this->assertSame($result, Zend_Locale_Format::getDate('July 4, 2007', array('locale' => 'en_US', 'date_format' => Zend_Locale_Format::STANDARD)));
     } catch (Zend_Locale_Exception $e) {
         $this->fail("exception expected");
     }
     try {
         // uses standard locale with standard format from this locale
         $expect = Zend_Locale_Format::getDate('July 4, 2007', array('locale' => Zend_Locale_Format::STANDARD));
         $testlocale = new Zend_Locale();
         $this->assertEquals($testlocale->toString(), $expect['locale']);
     } catch (Zend_Locale_Exception $e) {
         $this->fail("exception expected");
     }
     Zend_Locale_Format::setOptions(array('date_format' => null, 'locale' => null));
     // test tearDown
 }
Exemplo n.º 9
0
 /**
  * test setLocaleFailedRoot
  * expected true
  */
 public function testsetLocaleFailedRoot()
 {
     $value = new Zend_Locale();
     $value->setLocale('xx_AA');
     $this->assertEquals($value->toString(), 'root', 'Environment Locale not set');
 }
Exemplo n.º 10
0
 /**
  * Sets a new locale for data retreivement
  * Returned is the really set locale.
  * 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
  * @return string
  */
 public function setLocale($locale = null)
 {
     if ($locale instanceof Zend_Locale) {
         $this->_locale = $locale->toString();
     } else {
         if (!($this->_locale = Zend_Locale::isLocale($locale, true))) {
             require_once 'Zend/Currency/Exception.php';
             throw new Zend_Currency_Exception("Given locale ({$locale}) does not exist");
         }
     }
     // 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->getLocale();
 }
Exemplo n.º 11
0
 /**
  * Creates a currency instance. Every supressed parameter is used from the actual or the given locale.
  *
  * @param  string              $currency  OPTIONAL currency short name
  * @param  string              $script    OPTIONAL script name
  * @param  string|Zend_Locale  $locale    OPTIONAL locale name
  * @return Zend_Currency
  * @throws Zend_Currency_Exception
  */
 public function __construct($currency = null, $script = null, $locale = null)
 {
     // supporting flexible parameters
     $params = array(1 => $currency, 2 => $locale, 3 => $script);
     foreach ($params as $num => $param) {
         // get the locale
         if ($param instanceof Zend_Locale) {
             $param = $param->toString();
         }
         if (($locale = Zend_Locale::isLocale($param)) && strlen($param) > 4) {
             if ($locale != $param) {
                 throw new Zend_Currency_Exception("Unknown locale or locale without a region passed");
             }
             if (!empty($this->_locale)) {
                 throw new Zend_Currency_Exception("Multiple locales passed. Please provide only one locale");
             }
             if ($param instanceof Zend_Locale) {
                 $param = $param->toString();
             }
             $this->_locale = $param;
             // get the currency short name
         } else {
             if (is_string($param) && strlen($param) == 3) {
                 if (!empty($this->_shortName)) {
                     throw new Zend_Currency_Exception("Multiple currencies passed. Please provide only one currency");
                 }
                 $this->_shortName = $param;
                 // get the script name
             } else {
                 if (is_string($param) && strlen($param) == 4) {
                     if (!empty($this->_script)) {
                         throw new Zend_Currency_Exception("Multiple number script names passed. Please provide only one script");
                     }
                     try {
                         Zend_Locale_Format::convertNumerals('0', $param);
                     } catch (Exception $e) {
                         throw new Zend_Currency_Exception($e->getMessage());
                     }
                     $this->_script = $param;
                     // unknown data passed in this param
                 } else {
                     if ($param !== null) {
                         throw new Zend_Currency_Exception("Unknown locale '{$param}' passed with param #{$num}, locale must include the region");
                     }
                 }
             }
         }
     }
     // if no locale is passed, use standard locale
     if (empty($this->_locale)) {
         $locale = new Zend_Locale();
         $this->_locale = $locale->toString();
     }
     // get/check the shortname
     $data = Zend_Locale_Data::getContent(null, 'currencyforregionlist');
     if (!empty($this->_shortName)) {
         if (!in_array($this->_shortName, $data)) {
             throw new Zend_Currency_Exception("Unknown currency '{$this->_shortName}' passed");
         }
     } else {
         if (array_key_exists(substr($this->_locale, strpos($this->_locale, '_') + 1), $data)) {
             $this->_shortName = $data[substr($this->_locale, strpos($this->_locale, '_') + 1)];
         }
     }
     // get the fullname
     $names = Zend_Locale_Data::getContent($this->_locale, 'currencynames', substr($this->_locale, strpos($this->_locale, '_') + 1));
     $this->_fullName = isset($names[$this->_shortName]) ? $names[$this->_shortName] : '';
     // get the symbol
     $symbols = Zend_Locale_Data::getContent($this->_locale, 'currencysymbols');
     $this->_symbol = isset($symbols[$this->_shortName]) ? $symbols[$this->_shortName] : '';
     // get the format
     $this->_updateFormat();
     $this->_usedSign = self::NO_SYMBOL;
     if (!empty($this->_symbol)) {
         $this->_usedSign = self::USE_SYMBOL;
     } else {
         if (!empty($this->_shortName)) {
             $this->_usedSign = self::USE_SHORTNAME;
         }
     }
     return $this;
 }
Exemplo n.º 12
0
 /**
  * Checks if a locale identifier is a real locale or not
  * Examples:
  * "en_XX" refers to "en", which returns true
  * "XX_yy" refers to "root", which returns false
  *
  * @param  string|Zend_Locale  $locale  Locale to check for
  * @param  boolean             $create  If true, create a default locale, if $locale is empty
  * @return false|string   false if given locale is not a locale, else the locale identifier is returned
  */
 public static function isLocale($locale, $create = false)
 {
     if (empty($locale) and $create === true) {
         $locale = new Zend_Locale();
     }
     if ($locale instanceof Zend_Locale) {
         return $locale->toString();
     }
     if (!is_string($locale)) {
         return false;
     }
     if (array_key_exists($locale, self::$_LocaleData)) {
         return $locale;
     } else {
         $locale = explode('_', $locale);
         if (array_key_exists($locale[0], self::$_LocaleData)) {
             return $locale[0];
         }
     }
     return false;
 }
 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));
     }
 }
Exemplo n.º 14
0
 /**
  * Set the locale the useragent had set.
  *
  * @param Zend-Locale $locale
  *
  * @return ShortUrl_Model_Call
  */
 public function setLocale(Zend_Locale $locale = null)
 {
     if (null === $locale) {
         $locale = new Zend_Locale();
     }
     $this->_locale = $locale->toString();
     return $this;
 }
Exemplo n.º 15
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());
 }
Exemplo n.º 16
0
 /**
  * Sets the locale option
  *
  * @param  mixed $locale
  * @return Zend_Validate_Date Provides a fluent interface
  */
 public function setLocale($locale)
 {
     /**
      * @see Zend_Locale
      */
     require_once 'Zend/Locale.php';
     if (!Zend_Locale::isLocale($locale)) {
         $locale = new Zend_Locale();
         $this->_locale = $locale->toString();
     } else {
         $this->_locale = $locale;
     }
     return $this;
 }
Exemplo n.º 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
     $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;
 }
Exemplo n.º 18
0
 /**
  * method for getting browser language
  * @return array $browser e.g. array ('language' => 'en', 'language_long => 'en_GB');
  */
 public static function getBrowserLang()
 {
     include_once "Zend/Locale.php";
     $zend_locale = new Zend_Locale(Zend_Locale::BROWSER);
     $browser = array();
     $browser['language'] = $zend_locale->getLanguage();
     $browser['language_long'] = $zend_locale->toString();
     return $browser;
 }
Exemplo n.º 19
0
 /**
  * test toString
  * expected string
  */
 public function testToString()
 {
     $value = new Zend_Locale('de_DE');
     $this->assertEquals($value->toString(), 'de_DE', 'Locale de_DE expected');
 }
Exemplo n.º 20
0
 /**
  * Запуск приложения
  */
 public static function run($config)
 {
     try {
         ##Zend_Loader::registerAutoload(); // pre-1.8
         #$autoloader = Zend_Loader_Autoloader::getInstance(); // 1.8+
         #$autoloader->setFallbackAutoloader(true);
         // Создание объекта конфигурации
         $conf = new Zend_Config($config);
         //--< Zend_Log setup
         /*
         						if ( !Zend_Registry::isRegistered('logger') && !empty($conf->logger) )
         						{
         							$logger = new Zend_Log();
         
         							if ( !empty($conf->logger->writer) ) {
         								$logger->addWriter(new Zend_Log_Writer_Stream($conf->logger->writer, 'w')); // we care about log length :)
         							}
         
         							if ( !empty($conf->logger->firebug) ) {
         								$logger->addWriter(new Zend_Log_Writer_Firebug());
         							}
         
         							Zend_Registry::set('logger', $logger);
         							l($_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . ' START');
         
         							#$filter = new Zend_Log_Filter_Priority(Zend_Log::WARN);
         							#$writer->addFilter($filter);
         							#$logger = new Zend_Log($writer);
         						}
         */
         //-->
         // Занесение объекта конфигурации в реестр
         Zend_Registry::set('conf', $conf);
         // @todo обоснование (пока нужно только для перевода форм, более нигде)
         try {
             $locale = new Zend_Locale($conf->locale);
             // ru_RU.UTF8 -> ru
         } catch (Zend_Locale_Exception $e) {
         }
         Zend_Locale::setDefault($locale->toString());
         Zend_Registry::set('Zend_Locale', $locale);
         // Инициализация Zend_Layout, настройка пути к макетам, а также имени главного макета
         Zend_Layout::startMvc(array('layoutPath' => $conf->path->layouts));
         // Получение объекта Zend_Layout
         $layout = Zend_Layout::getMvcInstance();
         // Инициализация объекта Zend_View
         #$view = new Zend_View();
         $view = $layout->getView();
         // since 4/28/2009
         if (!isset($conf->deprecated->noobjectkey)) {
             $view->partial()->setObjectKey('model');
             $view->partialLoop()->setObjectKey('model');
         }
         // Настройка расширения макетов
         #$layout->setViewSuffix('tpl');
         // Задание базового URL
         $view->baseUrl = $conf->url->base;
         // Задание пути для view части
         $view->setBasePath($conf->path->views);
         // Сначала скрипт ищется в проекте, а уже потом - в общей либе
         $view->addScriptPath($conf->path->viewsCommon . "scripts");
         // 53.2.3. View Script Paths: http://framework.zend.com/manual/en/zend.view.controllers.html#zend.view.controllers.script-paths
         $view->addScriptPath($conf->path->views . "scripts");
         //@todo!
         #$res = $view->getScriptPaths();
         #echo "DEBUG:<br><textarea rows=10 cols=100>" . print_r($res, 1) . "</textarea><br>";die;
         #[0] => /mnt/win_d/srv.ntfs/sites/php/zf_ed/application/views/scripts/
         #[1] => /srv/sites/php/library/Zx/application/views/scripts/
         #[2] => /mnt/win_d/srv.ntfs/sites/php/zf_ed/application/views/scripts/
         $view->addHelperPath('Zx/View/Helper/', 'Zx_View_Helper');
         // 53.4.2. Helper Paths: http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.paths
         // Установка объекта Zend_View
         $layout->setView($view);
         // Настройка расширения view скриптов с помощью Action помошников
         $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
         #$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer'); // использование помощника действия вне контроллера действия
         $viewRenderer->setView($view);
         Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
         #Zend_Controller_Action_HelperBroker::addPrefix('Zx_Controller_Action_Helper');
         // Создание объекта front контроллера
         $frontController = Zend_Controller_Front::getInstance();
         //--< Подключение файла с правилами маршрутизации
         $router = $frontController->getRouter();
         if (!isset($conf->deprecated->routes)) {
             $router->addConfig(new Zend_Config_Ini($conf->path->configs . 'routes.ini', 'default'), 'routes');
         } else {
             require $conf->path->settings . 'routes.php';
         }
         #if ($conf->routes) {$frontController->setRouter($router);}
         //-->
         $frontController->setBaseUrl($conf->url->base)->throwexceptions(true);
         self::_initCache($conf);
         self::_initDb();
         self::_initFrontController($frontController, $conf);
         self::_initZFDebug();
         // ZFDebug_Controller_Plugin_Debug
         // Smartycode_Http_Conditional (http://smartycode.com/performance/zend-framework-browser-caching/)
         #$frontController->registerPlugin(new Zx_Controller_Plugin_HttpConditional(), 101); //@todo TEST!!!
         //-->
         // Запуск приложения, в качестве параметра передаем путь к папке с контроллерами
         l('RUN');
         Zend_Controller_Front::run($frontController->getControllerDirectory());
         l('FINISH');
     } catch (Exception $e) {
         if (!empty($config['handlers']['error'])) {
             Error::catchException($e);
         } else {
             Zx_ErrorHandler::catchException($e);
         }
     }
 }
Exemplo n.º 21
0
 public function onView()
 {
     if (!empty($_SESSION['facebook_signup']) || !empty($_SESSION['twitter_signup']) || !empty($_SESSION['janrain_signup'])) {
         // Attempt to preload information
         if (!empty($_SESSION['facebook_signup'])) {
             try {
                 $facebookTable = Engine_Api::_()->getDbtable('facebook', 'user');
                 $facebook = $facebookTable->getApi();
                 $settings = Engine_Api::_()->getDbtable('settings', 'core');
                 if ($facebook && $settings->core_facebook_enable) {
                     // Get email address
                     $apiInfo = $facebook->api('/me');
                     // @TODO: Temporarily store FB user data session
                     // General
                     $form = $this->getForm();
                     if (($emailEl = $form->getElement('email')) && !$emailEl->getValue()) {
                         $emailEl->setValue($apiInfo['email']);
                     }
                     if (($usernameEl = $form->getElement('username')) && !$usernameEl->getValue()) {
                         $usernameEl->setValue(preg_replace('/[^A-Za-z]/', '', $apiInfo['name']));
                     }
                     // Locale
                     $localeObject = new Zend_Locale($apiInfo['locale']);
                     if (($localeEl = $form->getElement('locale')) && !$localeEl->getValue()) {
                         $localeEl->setValue($localeObject->toString());
                     }
                     if (($languageEl = $form->getElement('language')) && !$languageEl->getValue()) {
                         if (isset($languageEl->options[$localeObject->toString()])) {
                             $languageEl->setValue($localeObject->toString());
                         } else {
                             if (isset($languageEl->options[$localeObject->getLanguage()])) {
                                 $languageEl->setValue($localeObject->getLanguage());
                             }
                         }
                     }
                 }
             } catch (Exception $e) {
                 // Silence?
             }
         }
         // Attempt to preload information
         if (!empty($_SESSION['twitter_signup'])) {
             try {
                 $twitterTable = Engine_Api::_()->getDbtable('twitter', 'user');
                 $twitter = $twitterTable->getApi();
                 $settings = Engine_Api::_()->getDbtable('settings', 'core');
                 if ($twitter && $settings->core_twitter_enable) {
                     $accountInfo = $twitter->account->verify_credentials();
                     // General
                     $this->getForm()->populate(array('username' => preg_replace('/[^A-Za-z]/', '', $accountInfo->name), 'language' => $accountInfo->lang));
                 }
             } catch (Exception $e) {
                 // Silence?
             }
         }
         // Attempt to preload information
         if (!empty($_SESSION['janrain_signup']) && !empty($_SESSION['janrain_signup_info'])) {
             try {
                 $form = $this->getForm();
                 $info = $_SESSION['janrain_signup_info'];
                 if (($emailEl = $form->getElement('email')) && !$emailEl->getValue() && !empty($info['verifiedEmail'])) {
                     $emailEl->setValue($info['verifiedEmail']);
                 }
                 if (($emailEl = $form->getElement('email')) && !$emailEl->getValue() && !empty($info['email'])) {
                     $emailEl->setValue($info['email']);
                 }
                 if (($usernameEl = $form->getElement('username')) && !$usernameEl->getValue() && !empty($info['preferredUsername'])) {
                     $usernameEl->setValue(preg_replace('/[^A-Za-z]/', '', $info['preferredUsername']));
                 }
             } catch (Exception $e) {
                 // Silence?
             }
         }
     }
 }
Exemplo n.º 22
0
 public function getLocaleName()
 {
     return $this->zendLocale->toString();
 }
Exemplo n.º 23
0
 /**
  * test setLocale
  * expected true
  */
 public function testsetLocale()
 {
     $value = new Zend_Locale('de_DE');
     $value->setLocale('en_US');
     $this->assertEquals($value->toString(), 'en_US', 'Environment Locale not set');
     $value->setLocale('en_AA');
     $this->assertEquals($value->toString(), 'en', 'Environment Locale not set');
     $value->setLocale('xx_AA');
     $this->assertEquals($value->toString(), 'root', 'Environment Locale not set');
 }
Exemplo n.º 24
0
 /**
  * Creates a currency instance. Every supressed parameter is used from the actual or the given locale.
  *
  * @param  string              $currency  OPTIONAL currency short name
  * @param  string              $script    OPTIONAL script name
  * @param  string|Zend_Locale  $locale    OPTIONAL locale name
  * @return Zend_Currency
  * @throws Zend_Currency_Exception
  */
 public function __construct($currency = null, $script = null, $locale = null)
 {
     // supporting flexible parameters
     $params = array(1 => $currency, 2 => $locale, 3 => $script);
     $currency = $locale = $script = false;
     foreach ($params as $num => $param) {
         // get the locale
         if ($locale = Zend_Locale::isLocale($param) and strlen($locale) > 4) {
             if (empty($this->_currencyLocale)) {
                 $this->_setCurrencyLocale($locale);
             } else {
                 throw new Zend_Currency_Exception("Multiple locales passed. Only one locale allowed");
             }
             // get the currency short name
         } else {
             if (is_string($param) && strlen($param) == 3) {
                 if (empty($this->_currencyShortName)) {
                     $this->_setCurrencyShortName($param);
                 } else {
                     throw new Zend_Currency_Exception("Multiple currencies passed. Only one currency allowed");
                 }
                 // get the script name
             } else {
                 if (is_string($param) && strlen($param) == 4) {
                     if (empty($this->_numberScript)) {
                         $this->_setNumberScript($param);
                     } else {
                         throw new Zend_Currency_Exception("Multiple number script names passed. Only one script name allowed");
                     }
                     // unknown data passed in this param
                 } else {
                     if ($param !== null) {
                         throw new Zend_Currency_Exception("Unknown locale '{$param}' passed with param #{$num}, locale must include the region");
                     }
                 }
             }
         }
     }
     // if no locale is passed, use standard locale
     if (empty($this->_currencyLocale)) {
         $locale = new Zend_Locale();
         $this->_setCurrencyLocale($locale->toString());
     }
     //getting the data related to this currency
     $this->_updateFullName()->_updateShortName()->_updateSymbol()->_updateFormat();
     return $this;
 }
Exemplo n.º 25
0
    /**
     * Checks if a locale identifier is a real locale or not
     * Examples:
     * "en_XX" refers to "en", which returns true
     * "XX_yy" refers to "root", which returns false
     *
     * @param  string|Zend_Locale  $locale  Locale to check for
     * @param  boolean             $create  If true, create a default locale, if $locale is empty
     * @return false|string   false if given locale is not a locale, else the locale identifier is returned
     */
    public static function isLocale($locale, $create = false)
    {
        if (empty($locale) and ($create === true)) {
            $locale = new Zend_Locale();
        }
        if ($locale instanceof Zend_Locale) {
            return $locale->toString();
        }
        if (!is_string($locale)) {
            return false;
        }
        if (empty(self::$_auto)) {
            $temp = new Zend_Locale($locale);
            self::$_auto        = $temp->getDefault(null, false);
            self::$_browser     = $temp->getDefault(self::BROWSER, false);
            self::$_environment = $temp->getDefault(self::ENVIRONMENT, false);
        }
        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);
        }

        if (array_key_exists($locale, self::$_localeData)) {
            return $locale;
        } else {
            $locale = explode('_', $locale);
            if (array_key_exists($locale[0], self::$_localeData)) {
                return $locale[0];
            }
        }
        return false;
    }
Exemplo n.º 26
0
 /**
  * Create a new User object and fill it with default parameters.
  * The Zend_Locale with no parameter detects automatically the user locale
  */
 private function createAnonymousUser()
 {
     $user = new User();
     $user->setId(0);
     $timezone = Config::getInstance()->getString("properties/anonymousUserTimezone");
     $user->setTimezone($timezone);
     $zend_locale = new Zend_Locale();
     $user->setLocale($zend_locale->toString());
     return $user;
 }
Exemplo n.º 27
0
 /**
  * test setLocale
  * expected true
  */
 public function testsetLocale()
 {
     $value = new Zend_Locale('de_DE');
     $value->setLocale('en_US');
     $this->assertEquals('en_US', $value->toString());
     $value->setLocale('en_AA');
     $this->assertEquals('en', $value->toString());
     $value->setLocale('xx_AA');
     $this->assertEquals('root', $value->toString());
     $value->setLocale('auto');
     $this->assertTrue(is_string($value->toString()));
     $value->setLocale('browser');
     $this->assertTrue(is_string($value->toString()));
     $value->setLocale('environment');
     $this->assertTrue(is_string($value->toString()));
 }
Exemplo n.º 28
0
 public function load_icons()
 {
     if (!$this->post('msLanguage')) {
         return false;
     }
     $ch = Loader::helper('interface/flag', 'multilingual');
     Loader::library('3rdparty/Zend/Locale');
     // here's what we do. We load all locales, then we filter through all those that match the posted language code
     // and we return html for all regions in that language
     $locales = Zend_Locale::getLocaleList();
     $countries = array();
     $html = '';
     foreach ($locales as $locale => $none) {
         $zl = new Zend_Locale($locale);
         if ($zl->getLanguage() == $this->post('msLanguage') || $zl->toString() == $this->post('msLanguage')) {
             if ($zl->getRegion()) {
                 $countries[$zl->getRegion()] = Zend_Locale::getTranslation($zl->getRegion(), 'country', ACTIVE_LOCALE);
             }
         }
     }
     asort($countries);
     $i = 1;
     foreach ($countries as $region => $value) {
         $flag = $ch->getFlagIcon($region);
         if ($flag) {
             $checked = "";
             if ($this->post('selectedLanguageIcon') == $region) {
                 $checked = "checked=\"checked\"";
             } else {
                 if ($i == 1 && !$this->post('selectedLanguageIcon')) {
                     $checked = "checked=\"checked\"";
                 }
             }
             $html .= '<li><label><input type="radio" name="msIcon" ' . $checked . ' id="languageIcon' . $i . '" value="' . $region . '" onchange="ccm_multilingualUpdateLocale(\'' . $region . '\')" /><span class="image-wrapper">' . $flag . '' . $value . '</span></label></li>';
             $i++;
         }
     }
     if ($i == 1) {
         $html = "<li><label><span><strong>" . t('None') . "</strong></span></label></li>";
     }
     print $html;
     exit;
 }
Exemplo n.º 29
0
 /**
  * Returns true if both locales are equal
  *
  * @param  Zend_Locale $object Locale to check for equality
  * @return boolean
  */
 public function equals(Zend_Locale $object)
 {
     if ($object->toString() === $this->toString()) {
         return true;
     }
     return false;
 }
Exemplo n.º 30
0
 /**
  * Set the locale
  */
 function setLocale($locale = LOCALE)
 {
     //detect if local file with language string constants is available and load it
     $local_constants_file = ONXSHOP_PROJECT_DIR . "locales/{$locale}/constants.php";
     if (file_exists($local_constants_file)) {
         require_once $local_constants_file;
     }
     //load global language string constants file with fallback to en_GB
     $global_constants_file = ONXSHOP_DIR . "locales/{$locale}/constants.php";
     if (!file_exists($global_constants_file)) {
         $global_constants_file = ONXSHOP_DIR . "locales/en_GB.UTF-8/constants.php";
     }
     require_once $global_constants_file;
     //now set system locale
     setlocale(LC_ALL, LOCALE);
     //but for numbers keep english
     setlocale(LC_NUMERIC, 'en_GB.UTF-8');
     require_once 'lib/Zend/Locale.php';
     require_once 'lib/Zend/Currency.php';
     if (LOCALE == 'cs_CZ.UTF-8') {
         putenv("TZ=Europe/Prague");
         putenv("LANG=cs_CZ.UTF-8");
         date_default_timezone_set("Europe/Prague");
     } else {
         putenv("TZ=Europe/London");
         putenv("LANG=en_GB.UTF-8");
         date_default_timezone_set("Europe/London");
     }
     $Zend_locale = new Zend_Locale(substr($locale, 0, 5));
     $Zend_currency = new Zend_Currency($Zend_locale->toString());
     define('GLOBAL_LOCALE_CURRENCY', $Zend_currency->getShortName());
 }