Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.8/wp-includes/pomo/translations.php

    r10810 r11627  
    33 * Class for a set of entries for translation and their associated headers
    44 *
    5  * @version $Id: translations.php 35 2009-02-16 12:54:57Z nbachiyski $
     5 * @version $Id: translations.php 114 2009-05-11 17:30:38Z nbachiyski $
    66 * @package pomo
    77 * @subpackage translations
     
    2020     * @return bool true on success, false if the entry doesn't have a key
    2121     */
    22     function add_entry(&$entry) {
     22    function add_entry($entry) {
     23        if (is_array($entry)) {
     24            $entry = new Translation_Entry($entry);
     25        }
    2326        $key = $entry->key();
    2427        if (false === $key) return false;
    25         $this->entries[$key] = &$entry;
     28        $this->entries[$key] = $entry;
    2629        return true;
    2730    }
     
    8891        if ($translated && 0 <= $index && $index < $total_plural_forms &&
    8992                is_array($translated->translations) &&
    90                 count($translated->translations) == $total_plural_forms)
     93                isset($translated->translations[$index]))
    9194            return $translated->translations[$index];
    9295        else
     
    9497    }
    9598
     99    /**
     100     * Merge $other in the current object.
     101     *
     102     * @param Object &$other Another Translation object, whose translations will be merged in this one
     103     * @return void
     104     **/
     105    function merge_with(&$other) {
     106        $this->entries = array_merge($this->entries, $other->entries);
     107    }
     108}
     109
     110class Gettext_Translations extends Translations {
    96111    /**
    97112     * The gettext implmentation of select_plural_form.
     
    131146     * Adds parantheses to the inner parts of ternary operators in
    132147     * plural expressions, because PHP evaluates ternary oerators from left to right
    133      *
     148     * 
    134149     * @param string $expression the expression without parentheses
    135150     * @return string the expression with parentheses added
     
    159174        return rtrim($res, ';');
    160175    }
     176   
     177    function make_headers($translation) {
     178        $headers = array();
     179        // sometimes \ns are used instead of real new lines
     180        $translation = str_replace('\n', "\n", $translation);
     181        $lines = explode("\n", $translation);
     182        foreach($lines as $line) {
     183            $parts = explode(':', $line, 2);
     184            if (!isset($parts[1])) continue;
     185            $headers[trim($parts[0])] = trim($parts[1]);
     186        }
     187        return $headers;
     188    }
    161189
    162     /**
    163      * Merge $other in the current object.
    164      *
    165      * @param Object &$other Another Translation object, whose translations will be merged in this one
    166      * @return void
    167      **/
    168     function merge_with(&$other) {
    169         $this->entries = array_merge($this->entries, $other->entries);
     190    function set_header($header, $value) {
     191        parent::set_header($header, $value);
     192        if ('Plural-Forms' == $header)
     193            $this->_gettext_select_plural_form = $this->_make_gettext_select_plural_form($value);
    170194    }
     195
     196   
    171197}
    172198
Note: See TracChangeset for help on using the changeset viewer.