filename = $filename; $this->_loadFile(); } /** * Returns the translated string for T, or the original if none exists * * @param string Native string to look up a translation for * * @return string */ function T($str) { if (empty($this->strings[$str])) { return $str; } return $this->strings[$str]; } /** * Reads $size number of bytes * * @param integer Number of bytes to read * * @return string */ function _readBytes($size) { $stream = fread($this->file, 4 * $size); if ($this->bigEndian) { return unpack('N' . $size, $stream); } else { return unpack('V' . $size, $stream); } } /** * Lodas the MO data information into the stirng table */ function _loadFile() { $this->file = @fopen($this->filename, 'r'); if (!$this->file) { BSApp::debug("could not open MO file {$this->filename}"); return; } // read the magic number $stream = $this->_readBytes(1); $stream = dechex($stream[1]); if ($stream == '950412de') { $this->bigEndian = false; } else if ($stream == 'de120495') { $this->bigEndian = true; } else { throw new Exception('Invalid MO file format'); } // read the revision (unused in MOs) $this->_readBytes(1); // read the number of strings $count = $this->_readBytes(1); $count = $count[1]; // get the start positions of the original and translated tables $offsetO = $this->_readBytes(1); $offsetT = $this->_readBytes(1); fseek($this->file, $offsetO[1]); $tableO = $this->_readBytes(2 * $count); fseek($this->file, $offsetT[1]); $tableT = $this->_readBytes(2 * $count); for ($i = 0; $i < $count; $i++) { if ($tableO[$i * 2 + 1] > 0) { fseek($this->file, $tableO[$i * 2 + 2]); $O = fread($this->file, $tableO[$i * 2 + 1]); } if ($tableT[$i * 2 + 1] > 0) { fseek($this->file, $tableT[$i * 2 + 2]); $this->strings[$O] = fread($this->file, $tableT[$i * 2 + 1]); } } fclose($this->file); } } ?>