$void ) { if ( ! isset( $matched_pot_keys[ $old_key ] ) ) { $obsolete_strings_count++; } } $raw_po_text = AF_Translate_PO_Processor::generate_po_string( array_values( $unique_compiled_output ) ); $sanitized_po_text = self::deduplicate_raw_po_string( $raw_po_text ); if ( false === file_put_contents( $po_path, $sanitized_po_text ) ) { return false; } return array( 'new' => $new_strings_count, 'obsolete' => $obsolete_strings_count, ); } /** * Compiles clean standard plain-text raw .po files into machine-readable .mo formats. */ public static function compile_po_to_mo( $po_path, $mo_path ) { $po_path = self::resolve_canonical_path( $po_path ); $mo_path = self::resolve_canonical_path( $mo_path ); if ( ! file_exists( $po_path ) || ! class_exists( 'AF_Translate_PO_Processor' ) ) { return false; } $entries_parsed = AF_Translate_PO_Processor::parse_file( $po_path ); $entries = array(); foreach ( $entries_parsed as $entry ) { $id = isset( $entry['msgid'] ) ? (string) $entry['msgid'] : ''; if ( empty( $id ) ) { continue; } if ( ! empty( $entry['msgid_plural'] ) ) { $id .= "\x00" . $entry['msgid_plural']; } if ( ! empty( $entry['msgctxt'] ) ) { $id = $entry['msgctxt'] . "\x04" . $id; } $str_val = ''; if ( ! empty( $entry['msgstr'] ) ) { $str_val = implode( "\x00", $entry['msgstr'] ); } $entries[ $id ] = $str_val; } ksort( $entries ); $count = count( $entries ); if ( 0 === $count ) { return false; } $ids = ''; $strs = ''; $ids_offsets = array(); $strs_offsets = array(); foreach ( $entries as $id => $str ) { $ids_offsets[] = array( 'len' => strlen( $id ), 'pos' => strlen( $ids ) ); $ids .= $id . "\x00"; $strs_offsets[] = array( 'len' => strlen( $str ), 'pos' => strlen( $strs ) ); $strs .= $str . "\x00"; } $key_start = 28; $val_start = $key_start + ( $count * 8 ); $size_start = $val_start + ( $count * 8 ); $offsets_key = ''; foreach ( $ids_offsets as $offset ) { $offsets_key .= pack( 'VV', $offset['len'], $offset['pos'] + $size_start ); } $offsets_val = ''; foreach ( $strs_offsets as $offset ) { $offsets_val .= pack( 'VV', $offset['len'], $offset['pos'] + $size_start + strlen( $ids ) ); } $mo_header = pack( 'VvvIIIII', 0x950412de, 0, 0, $count, $key_start, $val_start, 0, 0 ); $mo_binary_data = $mo_header . $offsets_key . $offsets_val . $ids . $strs; return ( false !== file_put_contents( $mo_path, $mo_binary_data ) ); } }