예제 #1
0
        // attempt to compile MO direct to file via shell
        if ($msgfmt = LocoAdmin::msgfmt_command()) {
            try {
                $bytes = 0;
                loco_require('build/shell-compiled');
                define('WHICH_MSGFMT', $msgfmt);
                $mopath = loco_compile_mo_file($path, $mopath);
                $bytes = $mopath && file_exists($mopath) ? filesize($mopath) : 0;
            } catch (Exception $Ex) {
                error_log($Ex->getMessage(), 0);
            }
            if (!$bytes) {
                throw new Exception(sprintf(Loco::__('Failed to compile MO file with %s, check your settings'), WHICH_MSGFMT));
            }
            $response['compiled'] = $bytes;
            break;
        }
        // Fall back to in-built MO compiler - requires PO is parsed too
        $mo = LocoAdmin::msgfmt_native($po);
        $bytes = file_put_contents($mopath, $mo);
        if (!$bytes) {
            throw new Exception(Loco::__('Failed to write MO file'));
        }
        $response['compiled'] = $bytes;
        break;
    } catch (Exception $e) {
        $response['compiled'] = $e->getMessage();
        break;
    }
}
return $response;