web/wp-includes/pomo/translations.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * Class for a set of entries for translation and their associated headers
     3  * Class for a set of entries for translation and their associated headers
     4  *
     4  *
     5  * @version $Id: translations.php 291 2009-10-21 05:46:08Z nbachiyski $
     5  * @version $Id: translations.php 590 2010-12-20 19:58:37Z nbachiyski $
     6  * @package pomo
     6  * @package pomo
     7  * @subpackage translations
     7  * @subpackage translations
     8  */
     8  */
     9 
     9 
    10 require_once dirname(__FILE__) . '/entry.php';
    10 require_once dirname(__FILE__) . '/entry.php';
    27 		$key = $entry->key();
    27 		$key = $entry->key();
    28 		if (false === $key) return false;
    28 		if (false === $key) return false;
    29 		$this->entries[$key] = &$entry;
    29 		$this->entries[$key] = &$entry;
    30 		return true;
    30 		return true;
    31 	}
    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;
       
    43 		return true;
       
    44 	}
    32 
    45 
    33 	/**
    46 	/**
    34 	 * Sets $header PO header to $value
    47 	 * Sets $header PO header to $value
    35 	 *
    48 	 *
    36 	 * If the header already exists, it will be overwritten
    49 	 * If the header already exists, it will be overwritten
    66 	}
    79 	}
    67 
    80 
    68 	/**
    81 	/**
    69 	 * Given the number of items, returns the 0-based index of the plural form to use
    82 	 * Given the number of items, returns the 0-based index of the plural form to use
    70 	 *
    83 	 *
    71 	 * Here, in the base Translations class, the commong logic for English is implmented:
    84 	 * Here, in the base Translations class, the common logic for English is implemented:
    72 	 * 	0 if there is one element, 1 otherwise
    85 	 * 	0 if there is one element, 1 otherwise
    73 	 *
    86 	 *
    74 	 * This function should be overrided by the sub-classes. For example MO/PO can derive the logic
    87 	 * This function should be overrided by the sub-classes. For example MO/PO can derive the logic
    75 	 * from their headers.
    88 	 * from their headers.
    76 	 *
    89 	 *
   102 	 *
   115 	 *
   103 	 * @param Object &$other Another Translation object, whose translations will be merged in this one
   116 	 * @param Object &$other Another Translation object, whose translations will be merged in this one
   104 	 * @return void
   117 	 * @return void
   105 	 **/
   118 	 **/
   106 	function merge_with(&$other) {
   119 	function merge_with(&$other) {
   107 		$this->entries = array_merge($this->entries, $other->entries);
   120 		foreach( $other->entries as $entry ) {
       
   121 			$this->entries[$entry->key()] = $entry;
       
   122 		}
       
   123 	}
       
   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 		}
   108 	}
   132 	}
   109 }
   133 }
   110 
   134 
   111 class Gettext_Translations extends Translations {
   135 class Gettext_Translations extends Translations {
   112 	/**
   136 	/**