예제 #1
0
파일: PO.php 프로젝트: ahastudio/moniwiki
 /**
  * Save PO file
  *
  * @access  public
  * @return  mixed   Returns true on success or PEAR_Error on failure.
  * @param   string  $file
  */
 function save($file = null)
 {
     if (!isset($file)) {
         $file = $this->file;
     }
     // open PO file
     if (!is_resource($fh = @fopen($file, 'w'))) {
         return parent::raiseError($php_errormsg . ' ' . $file);
     }
     // lock PO file exclusively
     if (!@flock($fh, LOCK_EX)) {
         @fclose($fh);
         return parent::raiseError($php_errormsg . ' ' . $file);
     }
     // write meta info
     if (count($this->meta)) {
         $meta = 'msgid ""' . "\nmsgstr " . '""' . "\n";
         foreach ($this->meta as $k => $v) {
             $meta .= '"' . $k . ': ' . $v . '\\n"' . "\n";
         }
         fwrite($fh, $meta . "\n");
     }
     // write strings
     foreach ($this->strings as $o => $t) {
         fwrite($fh, 'msgid "' . parent::prepare($o, true) . '"' . "\n" . 'msgstr "' . parent::prepare($t, true) . '"' . "\n\n");
     }
     //done
     @flock($fh, LOCK_UN);
     @fclose($fh);
     return true;
 }