Ejemplo n.º 1
0
 /**
  * Save editing file
  * @return json
  */
 public function saveEditingFile()
 {
     $filePath = $this->input->post('filePath');
     $content = $this->input->post('content');
     if (FileOperator::getInstatce()->updateFile($filePath, $content)) {
         return json_encode(array('success' => TRUE, 'data' => TRUE));
     } else {
         return json_encode(array('error' => TRUE, 'errors' => FileOperator::getInstatce()->getErrors()));
     }
 }
 public function toArray($name, $type, $lang, $langOn = TRUE)
 {
     $path = $this->getPoFileUrl($name, $type, $lang);
     if (!FileOperator::getInstatce()->checkFile($path, $langOn)) {
         $error = FileOperator::getInstatce()->getErrors();
         $this->setError($error['error']);
         return FALSE;
     } else {
         $po = file($path);
     }
     $origin = null;
     $this->po_settings = array();
     foreach ($po as $key => $line) {
         if (!($key > 2 && $origin)) {
             $this->prepareSettingsValues($line);
         }
         $first2symbols = substr($line, 0, 2);
         if (substr($line, 0, 1) == '#' && $first2symbols != '#:' && $first2symbols != '#,') {
             $comment = trim(substr($line, 2, -1));
             continue;
         }
         if ($first2symbols == '#,') {
             $fuzzy = TRUE;
             continue;
         }
         if ($first2symbols == '#:') {
             $links[] = trim(substr($line, 2, -1));
             continue;
         }
         if (substr($line, 0, 5) == 'msgid') {
             if (preg_match('/"(.*?)"$/', $line, $matches)) {
                 $origin = $matches[1];
                 if (!strlen($origin)) {
                     $origin = 0;
                 }
             }
             continue;
         }
         if (substr($line, 0, 6) == 'msgstr') {
             if ($origin) {
                 preg_match('/"(.*?)"$/', $line, $translation);
                 $translations[$origin] = array('translation' => isset($translation[1]) ? $translation[1] : '', 'comment' => $comment, 'links' => $links, 'fuzzy' => $fuzzy);
             }
             $fuzzy = FALSE;
             $comment = '';
             unset($links);
         }
     }
     $translations = $translations ? $translations : array();
     $result = array('settings' => $this->po_settings, 'po_array' => $translations);
     return $result;
 }