/** * Execute native msgfmt command * @param string po source * @return string binary mo source */ public static function msgfmt_native($po) { try { $conf = Loco::config(); loco_require('build/gettext-compiled'); $gen_hash = (bool) $conf['gen_hash']; $use_fuzzy = (bool) $conf['use_fuzzy']; $mo = loco_msgfmt($po, $gen_hash, $use_fuzzy); } catch (Exception $Ex) { error_log($Ex->getMessage(), 0); } if (!$mo) { throw new Exception(sprintf(Loco::__('Failed to compile MO file with built-in compiler'))); } return $mo; }
} // but package must exist so we can get POT or source /* @var $package LocoPackage */ loco_require('loco-packages', 'loco-locales'); $package = LocoPackage::get($name, $type); if (!$package) { throw new Exception(sprintf(Loco::__('Package not found called %s'), $name), 404); } $fname = basename($path); $podir = dirname($path); $dname = basename($podir); $ispot = LocoAdmin::is_pot($fname); $ftype = $ispot ? 'POT' : 'PO'; // handle file backups if file exists and enabled if (file_exists($path)) { $conf = Loco::config(); $num = (int) $conf['num_backups']; if (is_writable($podir)) { $dest = preg_replace('/\\.(pot?)$/i', '-backup-', $path); // delete oldest backups until we have $num-1 remaining if ($prev = glob($dest . '*')) { function _loco_sort_backups($f1, $f2) { $t1 = filemtime($f1); $t2 = filemtime($f2); return $t1 < $t2 ? -1 : ($t2 < $t1 ? 1 : 0); } usort($prev, '_loco_sort_backups'); foreach (array_slice($prev, max(0, $num - 1)) as $oldpath) { register_shutdown_function('unlink', $oldpath); }