Habari\Locale::load_file PHP Метод

load_file() приватный статический Метод

Load translations from a given file.
private static load_file ( string $domain, string $file ) : boolean
$domain string the domain to load the data into
$file string the file name
Результат boolean true if data was successfully loaded, false otherwise
    private static function load_file($domain, $file)
    {
        if (!file_exists($file)) {
            Error::raise(_t('No translations found for locale %s, domain %s!', array(self::$locale, $domain)));
            return false;
        }
        if (filesize($file) < 24) {
            Error::raise(_t('Invalid .MO file for locale %s, domain %s!', array(self::$locale, $domain)));
            return false;
        }
        $fp = fopen($file, 'rb');
        $data = fread($fp, filesize($file));
        fclose($fp);
        // determine endianness
        list(, $magic) = unpack('V1', substr($data, 0, 4));
        switch ($magic & 4294967295.0) {
            case (int) 0.0:
                $little_endian = true;
                break;
            case (int) 0.0:
                $little_endian = false;
                break;
            default:
                Error::raise(_t('Invalid magic number 0x%08x in %s!', array($magic, $file)));
                return false;
        }
        $revision = substr($data, 4, 4);
        if ($revision != 0) {
            Error::raise(_t('Unknown revision number %d in %s!', array($revision, $file)));
            return false;
        }
        $l = $little_endian ? 'V' : 'N';
        if ($data && strlen($data) >= 20) {
            $header = substr($data, 8, 12);
            $header = unpack("{$l}1msgcount/{$l}1msgblock/{$l}1transblock", $header);
            if ($header['msgblock'] + ($header['msgcount'] - 1) * 8 > filesize($file)) {
                Error::raise(_t('Message count (%d) out of bounds in %s!', array($header['msgcount'], $file)));
                return false;
            }
            $lo = "{$l}1length/{$l}1offset";
            for ($msgindex = 0; $msgindex < $header['msgcount']; $msgindex++) {
                $msginfo = unpack($lo, substr($data, $header['msgblock'] + $msgindex * 8, 8));
                $msgids = explode("", substr($data, $msginfo['offset'], $msginfo['length']));
                $transinfo = unpack($lo, substr($data, $header['transblock'] + $msgindex * 8, 8));
                $transids = explode("", substr($data, $transinfo['offset'], $transinfo['length']));
                self::$messages[$domain][$msgids[0]] = array($msgids, $transids);
            }
        }
        // setup plural functionality
        self::$plural_function = self::get_plural_function(self::$messages[$domain][''][1][0]);
        // only use locale if we actually read something
        return count(self::$messages) > 0;
    }