WordPress.org

Make WordPress Core

Changeset 22349


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

Sync POMO with GlotPress

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

Location:
trunk/wp-includes/pomo
Files:
5 edited

Legend:

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

    r18528 r22349  
    33 * Contains Translation_Entry class
    44 *
    5  * @version $Id: entry.php 621 2011-06-13 12:21:50Z nbachiyski $
     5 * @version $Id: entry.php 718 2012-10-31 00:32:02Z nbachiyski $
    66 * @package pomo
    77 * @subpackage entry
     
    6666        return is_null($this->context)? $this->singular : $this->context.chr(4).$this->singular;
    6767    }
    68    
     68
    6969    function merge_with(&$other) {
    7070        $this->flags = array_unique( array_merge( $this->flags, $other->flags ) );
     
    7373            $this->extracted_comments .= $other->extracted_comments;
    7474        }
    75        
     75
    7676    }
    7777}
  • 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
  • trunk/wp-includes/pomo/po.php

    r18528 r22349  
    33 * Class for working with PO files
    44 *
    5  * @version $Id: po.php 589 2010-12-18 01:40:57Z nbachiyski $
     5 * @version $Id: po.php 718 2012-10-31 00:32:02Z nbachiyski $
    66 * @package pomo
    77 * @subpackage po
     
    1919if ( !class_exists( 'PO' ) ):
    2020class PO extends Gettext_Translations {
    21    
     21
    2222    var $comments_before_headers = '';
    2323
     
    8181        return fclose($fh);
    8282    }
    83    
     83
    8484    /**
    8585     * Text to include as a comment before the start of the PO contents
    86      * 
     86     *
    8787     * Doesn't need to include # in the beginning of lines, these are added automatically
    8888     */
     
    121121        return $po;
    122122    }
    123    
     123
    124124    /**
    125125     * Gives back the original string from a PO-formatted string
    126      * 
     126     *
    127127     * @static
    128128     * @param string $string PO-formatted string
     
    154154
    155155    /**
    156      * Inserts $with in the beginning of every new line of $string and 
     156     * Inserts $with in the beginning of every new line of $string and
    157157     * returns the modified string
    158158     *
     
    230230        }
    231231        PO::read_line($f, 'clear');
    232         return $res !== false;
    233     }
    234    
     232        if ( false === $res ) {
     233            return false;
     234        }
     235        if ( ! $this->headers && ! $this->entries ) {
     236            return false;
     237        }
     238        return true;
     239    }
     240
    235241    function read_entry($f, $lineno = 0) {
    236242        $entry = new Translation_Entry();
     
    337343        return array('entry' => $entry, 'lineno' => $lineno);
    338344    }
    339    
     345
    340346    function read_line($f, $action = 'read') {
    341347        static $last_line = '';
     
    350356        }
    351357        $line = $use_last_line? $last_line : fgets($f);
     358        $line = gp_endswith( $line, "\r\n" )? rtrim( $line, "\r\n" ) . "\n" : $line;
    352359        $last_line = $line;
    353360        $use_last_line = false;
    354361        return $line;
    355362    }
    356    
     363
    357364    function add_comment_to_entry(&$entry, $po_comment_line) {
    358365        $first_two = substr($po_comment_line, 0, 2);
     
    368375        }
    369376    }
    370    
     377
    371378    function trim_quotes($s) {
    372379        if ( substr($s, 0, 1) == '"') $s = substr($s, 1);
  • trunk/wp-includes/pomo/streams.php

    r18528 r22349  
    44 * Based on the classes from Danilo Segan <danilo@kvota.net>
    55 *
    6  * @version $Id: streams.php 597 2011-01-16 20:14:36Z nbachiyski $
     6 * @version $Id: streams.php 718 2012-10-31 00:32:02Z nbachiyski $
    77 * @package pomo
    88 * @subpackage streams
     
    1111if ( !class_exists( 'POMO_Reader' ) ):
    1212class POMO_Reader {
    13    
     13
    1414    var $endian = 'little';
    1515    var $_post = '';
    16    
     16
    1717    function POMO_Reader() {
    1818        $this->is_overloaded = ((ini_get("mbstring.func_overload") & 2) != 0) && function_exists('mb_substr');
    1919        $this->_pos = 0;
    2020    }
    21    
     21
    2222    /**
    2323     * Sets the endianness of the file.
     
    5858        return unpack($endian_letter.$count, $bytes);
    5959    }
    60    
    61    
     60
     61
    6262    function substr($string, $start, $length) {
    6363        if ($this->is_overloaded) {
     
    6767        }
    6868    }
    69    
     69
    7070    function strlen($string) {
    7171        if ($this->is_overloaded) {
     
    7575        }
    7676    }
    77    
     77
    7878    function str_split($string, $chunk_size) {
    7979        if (!function_exists('str_split')) {
     
    8787        }
    8888    }
    89    
    90        
     89
     90
    9191    function pos() {
    9292        return $this->_pos;
     
    9696        return true;
    9797    }
    98    
     98
    9999    function close() {
    100100        return true;
     
    109109        $this->_f = fopen($filename, 'rb');
    110110    }
    111    
     111
    112112    function read($bytes) {
    113113        return fread($this->_f, $bytes);
    114114    }
    115    
     115
    116116    function seekto($pos) {
    117117        if ( -1 == fseek($this->_f, $pos, SEEK_SET)) {
     
    121121        return true;
    122122    }
    123    
     123
    124124    function is_resource() {
    125125        return is_resource($this->_f);
    126126    }
    127    
     127
    128128    function feof() {
    129129        return feof($this->_f);
    130130    }
    131    
     131
    132132    function close() {
    133133        return fclose($this->_f);
    134134    }
    135    
     135
    136136    function read_all() {
    137137        $all = '';
     
    149149 */
    150150class POMO_StringReader extends POMO_Reader {
    151    
     151
    152152    var $_str = '';
    153    
     153
    154154    function POMO_StringReader($str = '') {
    155155        parent::POMO_Reader();
     
    179179        return $this->substr($this->_str, $this->_pos, $this->strlen($this->_str));
    180180    }
    181    
     181
    182182}
    183183endif;
  • trunk/wp-includes/pomo/translations.php

    r18827 r22349  
    33 * Class for a set of entries for translation and their associated headers
    44 *
    5  * @version $Id: translations.php 590 2010-12-20 19:58:37Z nbachiyski $
     5 * @version $Id: translations.php 718 2012-10-31 00:32:02Z nbachiyski $
    66 * @package pomo
    77 * @subpackage translations
     
    3030        return true;
    3131    }
    32    
     32
    3333    function add_entry_or_merge($entry) {
    3434        if (is_array($entry)) {
     
    8282     * Given the number of items, returns the 0-based index of the plural form to use
    8383     *
    84      * Here, in the base Translations class, the common logic for English is implemented:
     84     * Here, in the base Translations class, the common logic for English is implmented:
    8585     *  0 if there is one element, 1 otherwise
    8686     *
     
    122122        }
    123123    }
    124    
     124
    125125    function merge_originals_with(&$other) {
    126126        foreach( $other->entries as $entry ) {
     
    149149        return call_user_func($this->_gettext_select_plural_form, $count);
    150150    }
    151    
     151
    152152    function nplurals_and_expression_from_header($header) {
    153153        if (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s+plural\s*=\s*(.+)$/', $header, $matches)) {
     
    175175     * Adds parantheses to the inner parts of ternary operators in
    176176     * plural expressions, because PHP evaluates ternary oerators from left to right
    177      * 
     177     *
    178178     * @param string $expression the expression without parentheses
    179179     * @return string the expression with parentheses added
     
    203203        return rtrim($res, ';');
    204204    }
    205    
     205
    206206    function make_headers($translation) {
    207207        $headers = array();
     
    216216        return $headers;
    217217    }
    218    
     218
    219219    function set_header($header, $value) {
    220220        parent::set_header($header, $value);
     
    235235    var $entries = array();
    236236    var $headers = array();
    237    
     237
    238238    function add_entry($entry) {
    239239        return true;
Note: See TracChangeset for help on using the changeset viewer.