prepare( "SELECT string_id, position_in_page FROM {$wpdb->prefix}icl_string_positions WHERE kind=%d AND string_id IN(%s)", ICL_STRING_TRANSLATION_STRING_TRACKING_TYPE_SOURCE, implode( ',', $ids )); $res = $wpdb->get_results( $sql_prepared ); foreach ( $res as $row ) { $positions[ $row->string_id ] = $row->position_in_page; } } foreach ( $strings as $s ) { $po .= PHP_EOL; if ( ! $pot_only && isset( $s[ 'translations' ] ) && isset( $s[ 'translations' ][ key( $s[ 'translations' ] ) ][ 'value' ] ) ) { $translation = $s[ 'translations' ][ key( $s[ 'translations' ] ) ][ 'value' ]; if ( $translation != '' && $s[ 'translations' ][ key( $s[ 'translations' ] ) ][ 'status' ] != ICL_TM_COMPLETE ) { $po .= '#, fuzzy' . PHP_EOL; } } else { $translation = ''; } if ( isset( $positions[ $s[ 'string_id' ] ] ) ) { $exp = @explode( '::', $positions[ $s[ 'string_id' ] ] ); $file = @file( $exp[ 0 ] ); } else { unset( $file ); unset( $exp ); } $po_single = ''; if ( isset( $file ) && isset( $exp ) ) { $line_number = $exp[ 1 ]; $line_number--; // Make it 0 base $line_number -= 2; // Go back 2 lines if ( $line_number < 0 ) { $line_number = 0; } for ( $line = 0; $line < 3; $line++ ) { $po_single .= '#: ' . @trim( $file[ $line_number + $line ] ) . PHP_EOL; } } $po_single .= '# wpml-name: ' . $s[ 'name' ] . PHP_EOL; if ( $s[ 'gettext_context' ] ) { $po_single .= 'msgctxt "' . $s[ 'gettext_context' ] . '"' . PHP_EOL; } $po_single .= 'msgid ' . self::output_string( $s[ 'value' ] ) . PHP_EOL; $po_single .= 'msgstr ' . self::output_string( $translation ) . PHP_EOL; $po .= $po_single; } return $po; } private static function output_string( $str ) { if ( strstr( $str, "\n" ) ) { $str = str_replace( "\r", "", $str ); $lines = explode( "\n", $str ); $str = '""'; foreach ( $lines as $line ) { $str .= PHP_EOL . '"' . self::addslashes( $line ) . '\n"' ; } } else { $str = '"' . self::addslashes( $str ) . '"'; } return $str; } private static function addslashes ( $str ) { $str = str_replace( '\\', '\\\\', $str ); $str = str_replace( '"', '\"', $str ); return $str; } }