Make WordPress Core


Ignore:
Timestamp:
08/11/2011 04:29:35 AM (14 years ago)
Author:
nbachiyski
Message:

Sync pomo library with the current GlotPress version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/pomo/mo.php

    r13830 r18528  
    33 * Class for working with MO files
    44 *
    5  * @version $Id: mo.php 406 2010-02-07 11:10:24Z nbachiyski $
     5 * @version $Id: mo.php 602 2011-01-30 12:43:29Z nbachiyski $
    66 * @package pomo
    77 * @subpackage mo
     
    3131        $fh = fopen($filename, 'wb');
    3232        if ( !$fh ) return false;
     33        $res = $this->export_to_file_handle( $fh );
     34        fclose($fh);
     35        return $res;
     36    }
     37   
     38    function export() {
     39        $tmp_fh = fopen("php://temp", 'r+');
     40        if ( !$tmp_fh ) return false;
     41        $this->export_to_file_handle( $tmp_fh );
     42        rewind( $tmp_fh );
     43        return stream_get_contents( $tmp_fh );
     44    }
     45   
     46    function export_to_file_handle($fh) {
    3347        $entries = array_filter($this->entries, create_function('$e', 'return !empty($e->translations);'));
    3448        ksort($entries);
     
    4458            $translations_lenghts_addr, $size_of_hash, $hash_addr));
    4559        fseek($fh, $originals_lenghts_addr);
    46 
     60       
    4761        // headers' msgid is an empty string
    4862        fwrite($fh, pack('VV', 0, $current_addr));
     
    5670            $current_addr += $length + 1; // account for the NULL byte after
    5771        }
    58 
     72       
    5973        $exported_headers = $this->export_headers();
    6074        fwrite($fh, pack('VV', strlen($exported_headers), $current_addr));
    6175        $current_addr += strlen($exported_headers) + 1;
    6276        $translations_table = $exported_headers . chr(0);
    63 
     77       
    6478        foreach($entries as $entry) {
    6579            $translations_table .= $this->export_translations($entry) . chr(0);
     
    6882            $current_addr += $length + 1;
    6983        }
    70 
     84       
    7185        fwrite($fh, $originals_table);
    7286        fwrite($fh, $translations_table);
    73         fclose($fh);
    74     }
    75 
     87        return true;
     88    }
     89   
    7690    function export_original($entry) {
    7791        //TODO: warnings for control characters
     
    8195        return $exported;
    8296    }
    83 
     97   
    8498    function export_translations($entry) {
    8599        //TODO: warnings for control characters
    86100        return implode(chr(0), $entry->translations);
    87101    }
    88 
     102   
    89103    function export_headers() {
    90104        $exported = '';
     
    194208     * Build a Translation_Entry from original string and translation strings,
    195209     * found in a MO file
    196      *
     210     * 
    197211     * @static
    198212     * @param string $original original string to translate from MO file. Might contain
Note: See TracChangeset for help on using the changeset viewer.