$bytes, 'filename' => basename($path), 'modified' => LocoAdmin::format_datetime( filemtime($path) ), ); // flush package from cache, so it's regenerated next list view with new stats $package->uncache(); // attempt to write MO file also, but may fail for numerous reasons. while( ! $ispot ){ try { // check target MO path before compiling $mopath = preg_replace( '/\.po$/', '.mo', $path ); if( ! file_exists($mopath) && ! is_writable( dirname($mopath) ) ){ throw new Exception( __('Cannot create MO file','loco-legacy') ); } else if( file_exists($mopath) && ! is_writable($mopath) ){ throw new Exception( __('Cannot overwrite MO file','loco-legacy') ); } // 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( __('Failed to compile MO file with %s, check your settings','loco-legacy'), 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( __('Failed to write MO file','loco-legacy') ); } $response['compiled'] = $bytes; break; } catch( Exception $e ){ $response['compiled'] = $e->getMessage(); break; } } return $response;