Make WordPress Core


Ignore:
Timestamp:
10/31/2012 10:13:51 PM (13 years ago)
Author:
nbachiyski
Message:

Sync POMO with GlotPress

See http://glotpress.trac.wordpress.org/browser/trunk/pomo/

File:
1 edited

Legend:

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

    r21793 r22349  
    33 * Class for working with MO files
    44 *
    5  * @version $Id: mo.php 602 2011-01-30 12:43:29Z nbachiyski $
     5 * @version $Id: mo.php 718 2012-10-31 00:32:02Z nbachiyski $
    66 * @package pomo
    77 * @subpackage mo
     
    3535        return $res;
    3636    }
    37    
     37
    3838    function export() {
    3939        $tmp_fh = fopen("php://temp", 'r+');
     
    4343        return stream_get_contents( $tmp_fh );
    4444    }
    45    
     45
     46    function is_entry_good_for_export( $entry ) {
     47        if ( empty( $entry->translations ) ) {
     48            return false;
     49        }
     50
     51        if ( !array_filter( $entry->translations ) ) {
     52            return false;
     53        }
     54
     55        return true;
     56    }
     57
    4658    function export_to_file_handle($fh) {
    47         $entries = array_filter($this->entries, create_function('$e', 'return !empty($e->translations);'));
     59        $entries = array_filter( $this->entries, array( $this, 'is_entry_good_for_export' ) );
    4860        ksort($entries);
    4961        $magic = 0x950412de;
     
    5870            $translations_lenghts_addr, $size_of_hash, $hash_addr));
    5971        fseek($fh, $originals_lenghts_addr);
    60        
     72
    6173        // headers' msgid is an empty string
    6274        fwrite($fh, pack('VV', 0, $current_addr));
     
    7082            $current_addr += $length + 1; // account for the NULL byte after
    7183        }
    72        
     84
    7385        $exported_headers = $this->export_headers();
    7486        fwrite($fh, pack('VV', strlen($exported_headers), $current_addr));
    7587        $current_addr += strlen($exported_headers) + 1;
    7688        $translations_table = $exported_headers . chr(0);
    77        
     89
    7890        foreach($entries as $entry) {
    7991            $translations_table .= $this->export_translations($entry) . chr(0);
     
    8294            $current_addr += $length + 1;
    8395        }
    84        
     96
    8597        fwrite($fh, $originals_table);
    8698        fwrite($fh, $translations_table);
    8799        return true;
    88100    }
    89    
     101
    90102    function export_original($entry) {
    91103        //TODO: warnings for control characters
     
    95107        return $exported;
    96108    }
    97    
     109
    98110    function export_translations($entry) {
    99111        //TODO: warnings for control characters
    100112        return implode(chr(0), $entry->translations);
    101113    }
    102    
     114
    103115    function export_headers() {
    104116        $exported = '';
     
    196208
    197209            if ('' === $original) {
    198                 $headers = $this->make_headers($translation);
    199                 $this->set_headers($headers);
     210                $this->set_headers($this->make_headers($translation));
    200211            } else {
    201212                $entry = &$this->make_entry($original, $translation);
     
    209220     * Build a Translation_Entry from original string and translation strings,
    210221     * found in a MO file
    211      * 
     222     *
    212223     * @static
    213224     * @param string $original original string to translate from MO file. Might contain
Note: See TracChangeset for help on using the changeset viewer.