Prado\I18N\core\Gettext\TGettext_MO::load PHP Метод

load() публичный Метод

Load MO file
public load ( string $file = null ) : mixed
$file string
Результат mixed Returns true on success or PEAR_Error on failure.
    function load($file = null)
    {
        if (!isset($file)) {
            $file = $this->file;
        }
        // open MO file
        if (!is_resource($this->_handle = @fopen($file, 'rb'))) {
            return false;
        }
        // lock MO file shared
        if (!@flock($this->_handle, LOCK_SH)) {
            @fclose($this->_handle);
            return false;
        }
        // read (part of) magic number from MO file header and define endianess
        //unpack returns a reference????
        $unpacked = unpack('c', $this->_read(4));
        switch ($magic = array_shift($unpacked)) {
            case -34:
                $be = false;
                break;
            case -107:
                $be = true;
                break;
            default:
                return false;
        }
        // check file format revision - we currently only support 0
        if (0 !== ($_rev = $this->_readInt($be))) {
            return false;
        }
        // count of strings in this file
        $count = $this->_readInt($be);
        // offset of hashing table of the msgids
        $offset_original = $this->_readInt($be);
        // offset of hashing table of the msgstrs
        $offset_translat = $this->_readInt($be);
        // move to msgid hash table
        fseek($this->_handle, $offset_original);
        // read lengths and offsets of msgids
        $original = array();
        for ($i = 0; $i < $count; $i++) {
            $original[$i] = array('length' => $this->_readInt($be), 'offset' => $this->_readInt($be));
        }
        // move to msgstr hash table
        fseek($this->_handle, $offset_translat);
        // read lengths and offsets of msgstrs
        $translat = array();
        for ($i = 0; $i < $count; $i++) {
            $translat[$i] = array('length' => $this->_readInt($be), 'offset' => $this->_readInt($be));
        }
        // read all
        for ($i = 0; $i < $count; $i++) {
            $this->strings[$this->_readStr($original[$i])] = $this->_readStr($translat[$i]);
        }
        // done
        @flock($this->_handle, LOCK_UN);
        @fclose($this->_handle);
        $this->_handle = null;
        // check for meta info
        if (isset($this->strings[''])) {
            $this->meta = parent::meta2array($this->strings['']);
            unset($this->strings['']);
        }
        return true;
    }