Автор: Uncle Cheese (unclecheese@leftandmain.com)
Наследование: implements MetaLanguageInterface
Пример #1
0
 public function indexAction()
 {
     if ($this->_getParam('language')) {
         $gimme = CampTemplate::singleton()->context();
         $gimme->language = MetaLanguage::createFromCode($this->_getParam('language'));
     }
 }
 /**
  * @Route("/recommendation/send")
  * @Route("/{lang}/recommendation/send")
  */
 public function showAction(Request $request, $lang = 'ar')
 {
     $templatesService = $this->container->get('newscoop.templates.service');
     $smarty = $templatesService->getSmarty();
     $gimme = $smarty->context();
     $gimme->language = \MetaLanguage::createFromCode($lang);
     $smarty->assign('gimme', $gimme);
     $request->setLocale($lang);
     $response = new Response();
     $response->headers->set('Content-Type', 'text/html');
     $response->setContent($templatesService->fetchTemplate('_view/form-recommendation.tpl'));
     return $response;
 }
Пример #3
0
 /**
  * Handler for the language change event.
  *
  * @param MetaLanguage $p_oldLanguage
  * @param MetaLanguage $p_newLanguage
  */
 private function setLanguageHandler(MetaLanguage $p_oldLanguage, MetaLanguage $p_newLanguage)
 {
     static $languageHandlerRunning = false;
     if ($languageHandlerRunning || $p_newLanguage->same_as($p_oldLanguage)) {
         return;
     }
     $languageHandlerRunning = true;
     $this->m_readonlyProperties['url']->language = $p_newLanguage;
     $this->m_objects['language'] = $p_newLanguage;
     if ($this->article->defined()) {
         $oldArticle = $this->m_objects['article'];
         $newArticle = new MetaArticle($p_newLanguage->number, $oldArticle->number);
         $this->setArticleHandler($oldArticle, $newArticle);
     }
     if ($this->section->defined() && !$this->m_objects['article']->defined()) {
         $oldSection = $this->m_objects['section'];
         $newSection = new MetaSection($oldSection->publication->identifier, $oldSection->issue->number, $p_newLanguage->number, $oldSection->number);
         $this->setSectionHandler($oldSection, $newSection);
     }
     if ($this->issue->defined() && !$this->m_objects['section']->defined()) {
         $oldIssue = $this->m_objects['issue'];
         $newIssue = new MetaIssue($oldIssue->publication->identifier, $p_newLanguage->number, $oldIssue->number);
         $this->setIssueHandler($oldIssue, $newIssue);
     }
     $languageHandlerRunning = false;
 }
Пример #4
0
 /**
  * Get language by code
  *
  * @param  string          $code
  * @param  MetaPublication $publication
  * @return MetaLanguage
  */
 private function _getLanguage($code, MetaPublication $publication)
 {
     $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
     $cacheKey = $cacheService->getCacheKey(array('CampURIShortNameLanguage', $code, $publication->name), 'language');
     if ($cacheService->contains($cacheKey)) {
         return $cacheService->fetch($cacheKey);
     } else {
         $language = $publication->default_language;
         if (!empty($code)) {
             $langArray = Language::GetLanguages(null, $code);
             if (is_array($langArray) && sizeof($langArray) == 1) {
                 $language = new MetaLanguage($langArray[0]->getLanguageId());
             }
         }
         if (!$language->defined()) {
             throw new InvalidArgumentException("Invalid language identifier in URL.", self::INVALID_LANGUAGE);
         }
         $cacheService->save($cacheKey, $language);
         return $language;
     }
 }