コード例 #1
0
ファイル: Panel.php プロジェクト: carrooi/nette-translator
 private function processRequest()
 {
     if ($this->httpRequest->isPost() && $this->httpRequest->isAjax() && $this->httpRequest->getHeader(self::XHR_HEADER)) {
         $data = json_decode(file_get_contents('php://input'), true);
         if ($data && isset($data[self::AJAX_ACTION_KEY])) {
             switch ($data[self::AJAX_ACTION_KEY]) {
                 case self::AJAX_ACTION_LOAD:
                     $message = $data[self::AJAX_MESSAGE_KEY];
                     if (!$this->translator->hasTranslation($message)) {
                         throw new \Exception();
                     }
                     $data = array('translation' => $this->translator->findTranslation($message));
                     $this->httpResponse->setContentType('application/json');
                     echo json_encode($data);
                     break;
                 case self::AJAX_ACTION_EDIT:
                     $message = $data[self::AJAX_MESSAGE_KEY];
                     $translation = $data[self::AJAX_TRANSLATION_KEY];
                     if (!$this->translator->hasTranslation($message)) {
                         throw new \Exception();
                     }
                     $info = $this->translator->getMessageInfo($message);
                     $data = $this->translator->_loadCategory($info['path'], $info['category']);
                     $data[$info['name']] = $translation;
                     $this->translator->getLoader()->save($info['path'], $info['category'], $this->translator->getLanguage(), $data);
                     $this->httpResponse->setContentType('application/json');
                     break;
                 default:
                     throw new \Exception();
                     break;
             }
         }
         exit;
     }
 }
コード例 #2
0
ファイル: Panel.php プロジェクト: klimesf/gettext-translator
 /**
  * Handles an incomuing request and saves the data if necessary.
  */
 private function processRequest()
 {
     if ($this->httpRequest->isPost() && $this->httpRequest->isAjax() && $this->httpRequest->getHeader($this->xhrHeader)) {
         $data = json_decode(file_get_contents('php://input'));
         if ($data) {
             if ($this->debugMode === true && $this->sessionStorage) {
                 $stack = isset($this->sessionStorage['stack']) ? $this->sessionStorage['stack'] : array();
             }
             $this->translator->lang = $data->{$this->languageKey};
             $file = $data->{$this->fileKey};
             unset($data->{$this->languageKey}, $data->{$this->fileKey});
             foreach ($data as $string => $value) {
                 $this->translator->setTranslation($string, $value, $file);
                 if ($this->debugMode === true && $this->sessionStorage && isset($stack[$string])) {
                     unset($stack[$string]);
                 }
             }
             $this->translator->save($file);
             if ($this->debugMode === true && $this->sessionStorage) {
                 $this->sessionStorage['stack'] = $stack;
             }
         }
         exit;
     }
 }