loadFile( $source_file ); if ( $create_source == true ) { $batch_size = 1000; //$batch_size = 999999; $batch = 0; $prev_batch = 0; $i = 0; $out = null; $max = count( $po_strings->getTranslations() ) - 1; echo "Max: $max\n"; foreach ( $po_strings->getTranslations() as $msg_obj ) { //echo "$i. $msgid\n"; $msgid = preg_replace('/[\x00-\x1F\x7F]/', '', $msg_obj->getId() ); $msgstr = trim( $msg_obj->getTranslation() ); if ( $msgid == '#' || $msgstr != '' ) { $i++; if ( $i < $max ) { continue; } } if ( $i == 0 || $out == null ) { echo "I = 0 OR Batch = 0\n"; $out = "\n"; $out .= "
\n"; } if ( $i > 0 && ( $i % $batch_size == 0 || $i == $max ) ) { $batch++; echo "New Batch = $batch\n"; } $out .= '' . htmlentities( $msgid ) . "\n"; $out .= "\n"; //Write the file. $output_file_name = str_replace( '.', '-'. $batch .'.', dirname( $outfile ) . DIRECTORY_SEPARATOR . basename( $outfile ) ); echo "Writing to: ". $output_file_name ."\n"; file_put_contents( $output_file_name, $out ); $out = null; } $prev_batch = $batch; $i++; } } else { //Load translated HTML files. echo "Loading Translated File\n"; $file_contents = file_get_contents( $infile ); $file_contents = preg_replace( '//iu', '', $file_contents ); $file_contents = preg_replace( '/.*<\/head>/iu', '', $file_contents ); $file_contents = preg_replace( '/
\n"; //$out .= $i.': '. str_replace('
', '(11)', $msgid) ."
\n"; if ( $batch != $prev_batch ) { echo "Writing...\n"; $out .= "
', '', '' ], '', $file_contents ); $lines = explode( '', $file_contents ); //var_dump($lines); if ( is_array( $lines ) ) { echo "Total Lines: " . count( $lines ) . "\n"; $i = 0; foreach ( $lines as $line ) { //Parse the string number if ( preg_match( '/(.*)/i', trim( $line ), $matches ) == true ) { if ( is_array( $matches ) && isset( $matches[1] ) && isset( $matches[2] ) ) { $msgid = html_entity_decode( $matches[1] ); $msgstr = preg_replace( '/\s\"\s/iu', '"', html_entity_decode( $matches[2] ) ); echo $i . ". Translating: " . $msgid . "\n"; echo " To: " . $msgstr . "\n"; $tmp_translation = $po_strings->find( null, $msgid ); if ( $tmp_translation ) { $tmp_translation->translate( $msgstr ); } else { echo "Failed to find translation key...\n"; } } else { echo "ERROR parsing line!\n"; } } else { echo "Failed to match line!\n"; } $i++; } } $po_generator = new PoGenerator(); $po_generator->generateFile( $po_strings, $outfile ); } } } ?>