Make WordPress Core

Changeset 18528


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

Sync pomo library with the current GlotPress version

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

Legend:

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

    r13228 r18528  
    33 * Contains Translation_Entry class
    44 *
    5  * @version $Id: entry.php 406 2010-02-07 11:10:24Z nbachiyski $
     5 * @version $Id: entry.php 621 2011-06-13 12:21:50Z nbachiyski $
    66 * @package pomo
    77 * @subpackage entry
     
    6666        return is_null($this->context)? $this->singular : $this->context.chr(4).$this->singular;
    6767    }
     68   
     69    function merge_with(&$other) {
     70        $this->flags = array_unique( array_merge( $this->flags, $other->flags ) );
     71        $this->references = array_unique( array_merge( $this->references, $other->references ) );
     72        if ( $this->extracted_comments != $other->extracted_comments ) {
     73            $this->extracted_comments .= $other->extracted_comments;
     74        }
     75       
     76    }
    6877}
    6978endif;
  • 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
  • trunk/wp-includes/pomo/po.php

    r13830 r18528  
    33 * Class for working with PO files
    44 *
    5  * @version $Id: po.php 406 2010-02-07 11:10:24Z nbachiyski $
     5 * @version $Id: po.php 589 2010-12-18 01:40:57Z nbachiyski $
    66 * @package pomo
    77 * @subpackage po
     
    1919if ( !class_exists( 'PO' ) ):
    2020class PO extends Gettext_Translations {
    21 
     21   
     22    var $comments_before_headers = '';
    2223
    2324    /**
     
    3233        }
    3334        $poified = PO::poify($header_string);
    34         return rtrim("msgid \"\"\nmsgstr $poified");
     35        if ($this->comments_before_headers)
     36            $before_headers = $this->prepend_each_line(rtrim($this->comments_before_headers)."\n", '# ');
     37        else
     38            $before_headers = '';
     39        return rtrim("{$before_headers}msgid \"\"\nmsgstr $poified");
    3540    }
    3641
     
    7681        return fclose($fh);
    7782    }
     83   
     84    /**
     85     * Text to include as a comment before the start of the PO contents
     86     *
     87     * Doesn't need to include # in the beginning of lines, these are added automatically
     88     */
     89    function set_comment_before_headers( $text ) {
     90        $this->comments_before_headers = $text;
     91    }
    7892
    7993    /**
     
    107121        return $po;
    108122    }
    109 
     123   
    110124    /**
    111125     * Gives back the original string from a PO-formatted string
    112      *
     126     * 
    113127     * @static
    114128     * @param string $string PO-formatted string
     
    140154
    141155    /**
    142      * 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 
    143157     * returns the modified string
    144158     *
     
    218232        return $res !== false;
    219233    }
    220 
     234   
    221235    function read_entry($f, $lineno = 0) {
    222236        $entry = new Translation_Entry();
     
    255269                }
    256270                // add comment
    257                 $this->add_comment_to_entry($entry, $line);
     271                $this->add_comment_to_entry($entry, $line);;
    258272            } elseif (preg_match('/^msgctxt\s+(".*")/', $line, $m)) {
    259273                if ($is_final($context)) {
     
    323337        return array('entry' => $entry, 'lineno' => $lineno);
    324338    }
    325 
     339   
    326340    function read_line($f, $action = 'read') {
    327341        static $last_line = '';
     
    340354        return $line;
    341355    }
    342 
     356   
    343357    function add_comment_to_entry(&$entry, $po_comment_line) {
    344358        $first_two = substr($po_comment_line, 0, 2);
     
    354368        }
    355369    }
    356 
     370   
    357371    function trim_quotes($s) {
    358372        if ( substr($s, 0, 1) == '"') $s = substr($s, 1);
  • trunk/wp-includes/pomo/streams.php

    r15590 r18528  
    44 * Based on the classes from Danilo Segan <danilo@kvota.net>
    55 *
    6  * @version $Id: streams.php 406 2010-02-07 11:10:24Z nbachiyski $
     6 * @version $Id: streams.php 597 2011-01-16 20:14:36Z 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.
    2424     *
    25      * @param string $endian 'big' or 'little'
     25     * @param $endian string 'big' or 'little'
    2626     */
    2727    function setEndian($endian) {
     
    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;
     
    107107    function POMO_FileReader($filename) {
    108108        parent::POMO_Reader();
    109         $this->_f = fopen($filename, 'r');
    110     }
    111 
     109        $this->_f = fopen($filename, 'rb');
     110    }
     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

    r13830 r18528  
    33 * Class for a set of entries for translation and their associated headers
    44 *
    5  * @version $Id: translations.php 406 2010-02-07 11:10:24Z nbachiyski $
     5 * @version $Id: translations.php 590 2010-12-20 19:58:37Z nbachiyski $
    66 * @package pomo
    77 * @subpackage translations
     
    2828        if (false === $key) return false;
    2929        $this->entries[$key] = &$entry;
     30        return true;
     31    }
     32   
     33    function add_entry_or_merge($entry) {
     34        if (is_array($entry)) {
     35            $entry = new Translation_Entry($entry);
     36        }
     37        $key = $entry->key();
     38        if (false === $key) return false;
     39        if (isset($this->entries[$key]))
     40            $this->entries[$key]->merge_with($entry);
     41        else
     42            $this->entries[$key] = &$entry;
    3043        return true;
    3144    }
     
    109122        }
    110123    }
     124   
     125    function merge_originals_with(&$other) {
     126        foreach( $other->entries as $entry ) {
     127            if ( !isset( $this->entries[$entry->key()] ) )
     128                $this->entries[$entry->key()] = $entry;
     129            else
     130                $this->entries[$entry->key()]->merge_with($entry);
     131        }
     132    }
    111133}
    112134
     
    127149        return call_user_func($this->_gettext_select_plural_form, $count);
    128150    }
    129 
     151   
    130152    function nplurals_and_expression_from_header($header) {
    131153        if (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s+plural\s*=\s*(.+)$/', $header, $matches)) {
     
    153175     * Adds parantheses to the inner parts of ternary operators in
    154176     * plural expressions, because PHP evaluates ternary oerators from left to right
    155      *
     177     * 
    156178     * @param string $expression the expression without parentheses
    157179     * @return string the expression with parentheses added
     
    181203        return rtrim($res, ';');
    182204    }
    183 
     205   
    184206    function make_headers($translation) {
    185207        $headers = array();
     
    194216        return $headers;
    195217    }
    196 
     218   
    197219    function set_header($header, $value) {
    198220        parent::set_header($header, $value);
     
    213235    var $entries = array();
    214236    var $headers = array();
    215 
     237   
    216238    function add_entry($entry) {
    217239        return true;
Note: See TracChangeset for help on using the changeset viewer.