web/wp-includes/pomo/entry.php
branchwordpress
changeset 109 03b0d1493584
child 132 4d4862461b8d
equal deleted inserted replaced
-1:000000000000 109:03b0d1493584
       
     1 <?php
       
     2 /**
       
     3  * Contains Translation_Entry class
       
     4  *
       
     5  * @version $Id: entry.php 115 2009-05-11 18:56:15Z nbachiyski $
       
     6  * @package pomo
       
     7  * @subpackage entry
       
     8  */
       
     9 
       
    10 
       
    11 /**
       
    12  * Translation_Entry class encapsulates a translatable string
       
    13  */
       
    14 class Translation_Entry {
       
    15 
       
    16 	/**
       
    17 	 * Whether the entry contains a string and its plural form, default is false
       
    18 	 *
       
    19 	 * @var boolean
       
    20 	 */
       
    21 	var $is_plural = false;
       
    22 
       
    23 	var $context = null;
       
    24 	var $singular = null;
       
    25 	var $plural = null;
       
    26 	var $translations = array();
       
    27 	var $translator_comments = '';
       
    28 	var $extracted_comments = '';
       
    29 	var $references = array();
       
    30 	var $flags = array();
       
    31 
       
    32 	/**
       
    33 	 * @param array $args associative array, support following keys:
       
    34 	 * 	- singular (string) -- the string to translate, if omitted and empty entry will be created
       
    35 	 * 	- plural (string) -- the plural form of the string, setting this will set {@link $is_plural} to true
       
    36 	 * 	- translations (array) -- translations of the string and possibly -- its plural forms
       
    37 	 * 	- context (string) -- a string differentiating two equal strings used in different contexts
       
    38 	 * 	- translator_comments (string) -- comments left by translators
       
    39 	 * 	- extracted_comments (string) -- comments left by developers
       
    40 	 * 	- references (array) -- places in the code this strings is used, in relative_to_root_path/file.php:linenum form
       
    41 	 * 	- flags (array) -- flags like php-format
       
    42 	 */
       
    43 	function Translation_Entry($args=array()) {
       
    44 		// if no singular -- empty object
       
    45 		if (!isset($args['singular'])) {
       
    46 			return;
       
    47 		}
       
    48 		// get member variable values from args hash
       
    49 		$object_varnames = array_keys(get_object_vars($this));
       
    50 		foreach ($args as $varname => $value) {
       
    51 			$this->$varname = $value;
       
    52 		}
       
    53 		if (isset($args['plural'])) $this->is_plural = true;
       
    54 		if (!is_array($this->translations)) $this->translations = array();
       
    55 		if (!is_array($this->references)) $this->references = array();
       
    56 		if (!is_array($this->flags)) $this->flags = array();
       
    57 	}
       
    58 
       
    59 	/**
       
    60 	 * Generates a unique key for this entry
       
    61 	 *
       
    62 	 * @return string|bool the key or false if the entry is empty
       
    63 	 */
       
    64 	function key() {
       
    65 		if (is_null($this->singular)) return false;
       
    66 		// prepend context and EOT, like in MO files
       
    67 		return is_null($this->context)? $this->singular : $this->context.chr(4).$this->singular;
       
    68 	}
       
    69 }
       
    70 ?>