function save($file = null)
{
if (!isset($file)) {
$file = $this->file;
}
// open MO file
if (!is_resource($this->_handle = @fopen($file, 'wb'))) {
return false;
}
// lock MO file exclusively
if (!@flock($this->_handle, LOCK_EX)) {
@fclose($this->_handle);
return false;
}
// write magic number
if ($this->writeBigEndian) {
$this->_write(pack('c*', 0x95, 0x4, 0x12, 0xde));
} else {
$this->_write(pack('c*', 0xde, 0x12, 0x4, 0x95));
}
// write file format revision
$this->_writeInt(0);
$count = count($this->strings) + ($meta = count($this->meta) ? 1 : 0);
// write count of strings
$this->_writeInt($count);
$offset = 28;
// write offset of orig. strings hash table
$this->_writeInt($offset);
$offset += $count * 8;
// write offset transl. strings hash table
$this->_writeInt($offset);
// write size of hash table (we currently ommit the hash table)
$this->_writeInt(0);
$offset += $count * 8;
// write offset of hash table
$this->_writeInt($offset);
// unshift meta info
if ($this->meta) {
$meta = '';
foreach ($this->meta as $key => $val) {
$meta .= $key . ': ' . $val . "\n";
}
$strings = array('' => $meta) + $this->strings;
} else {
$strings = $this->strings;
}
// write offsets for original strings
foreach (array_keys($strings) as $o) {
$len = strlen($o);
$this->_writeInt($len);
$this->_writeInt($offset);
$offset += $len + 1;
}
// write offsets for translated strings
foreach ($strings as $t) {
$len = strlen($t);
$this->_writeInt($len);
$this->_writeInt($offset);
$offset += $len + 1;
}
// write original strings
foreach (array_keys($strings) as $o) {
$this->_writeStr($o);
}
// write translated strings
foreach ($strings as $t) {
$this->_writeStr($t);
}
// done
@flock($this->_handle, LOCK_UN);
@fclose($this->_handle);
chmod($file, PRADO_CHMOD);
return true;
}