wp/wp-includes/pomo/entry.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
     5  * @version $Id: entry.php 1157 2015-11-20 04:30:11Z dd32 $
     5  * @version $Id: entry.php 1157 2015-11-20 04:30:11Z dd32 $
     6  * @package pomo
     6  * @package pomo
     7  * @subpackage entry
     7  * @subpackage entry
     8  */
     8  */
     9 
     9 
    10 if ( ! class_exists( 'Translation_Entry', false ) ):
    10 if ( ! class_exists( 'Translation_Entry', false ) ) :
    11 /**
    11 	/**
    12  * Translation_Entry class encapsulates a translatable string
    12 	 * Translation_Entry class encapsulates a translatable string
    13  */
    13 	 */
    14 class Translation_Entry {
    14 	class Translation_Entry {
    15 
    15 
    16 	/**
    16 		/**
    17 	 * Whether the entry contains a string and its plural form, default is false
    17 		 * Whether the entry contains a string and its plural form, default is false
    18 	 *
    18 		 *
    19 	 * @var boolean
    19 		 * @var boolean
    20 	 */
    20 		 */
    21 	var $is_plural = false;
    21 		var $is_plural = false;
    22 
    22 
    23 	var $context = null;
    23 		var $context             = null;
    24 	var $singular = null;
    24 		var $singular            = null;
    25 	var $plural = null;
    25 		var $plural              = null;
    26 	var $translations = array();
    26 		var $translations        = array();
    27 	var $translator_comments = '';
    27 		var $translator_comments = '';
    28 	var $extracted_comments = '';
    28 		var $extracted_comments  = '';
    29 	var $references = array();
    29 		var $references          = array();
    30 	var $flags = array();
    30 		var $flags               = array();
    31 
    31 
    32 	/**
    32 		/**
    33 	 * @param array $args associative array, support following keys:
    33 		 * @param array $args associative array, support following keys:
    34 	 * 	- singular (string) -- the string to translate, if omitted and empty entry will be created
    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
    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
    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
    37 		 *  - context (string) -- a string differentiating two equal strings used in different contexts
    38 	 * 	- translator_comments (string) -- comments left by translators
    38 		 *  - translator_comments (string) -- comments left by translators
    39 	 * 	- extracted_comments (string) -- comments left by developers
    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
    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
    41 		 *  - flags (array) -- flags like php-format
    42 	 */
    42 		 */
    43 	function __construct( $args = array() ) {
    43 		function __construct( $args = array() ) {
    44 		// if no singular -- empty object
    44 			// if no singular -- empty object
    45 		if (!isset($args['singular'])) {
    45 			if ( ! isset( $args['singular'] ) ) {
    46 			return;
    46 				return;
    47 		}
    47 			}
    48 		// get member variable values from args hash
    48 			// get member variable values from args hash
    49 		foreach ($args as $varname => $value) {
    49 			foreach ( $args as $varname => $value ) {
    50 			$this->$varname = $value;
    50 				$this->$varname = $value;
    51 		}
    51 			}
    52 		if (isset($args['plural']) && $args['plural']) $this->is_plural = true;
    52 			if ( isset( $args['plural'] ) && $args['plural'] ) {
    53 		if (!is_array($this->translations)) $this->translations = array();
    53 				$this->is_plural = true;
    54 		if (!is_array($this->references)) $this->references = array();
    54 			}
    55 		if (!is_array($this->flags)) $this->flags = array();
    55 			if ( ! is_array( $this->translations ) ) {
    56 	}
    56 				$this->translations = array();
    57 
    57 			}
    58 	/**
    58 			if ( ! is_array( $this->references ) ) {
    59 	 * PHP4 constructor.
    59 				$this->references = array();
    60 	 */
    60 			}
    61 	public function Translation_Entry( $args = array() ) {
    61 			if ( ! is_array( $this->flags ) ) {
    62 		self::__construct( $args );
    62 				$this->flags = array();
    63 	}
    63 			}
    64 
       
    65 	/**
       
    66 	 * Generates a unique key for this entry
       
    67 	 *
       
    68 	 * @return string|bool the key or false if the entry is empty
       
    69 	 */
       
    70 	function key() {
       
    71 		if ( null === $this->singular || '' === $this->singular ) return false;
       
    72 
       
    73 		// Prepend context and EOT, like in MO files
       
    74 		$key = !$this->context? $this->singular : $this->context.chr(4).$this->singular;
       
    75 		// Standardize on \n line endings
       
    76 		$key = str_replace( array( "\r\n", "\r" ), "\n", $key );
       
    77 
       
    78 		return $key;
       
    79 	}
       
    80 
       
    81 	/**
       
    82 	 * @param object $other
       
    83 	 */
       
    84 	function merge_with(&$other) {
       
    85 		$this->flags = array_unique( array_merge( $this->flags, $other->flags ) );
       
    86 		$this->references = array_unique( array_merge( $this->references, $other->references ) );
       
    87 		if ( $this->extracted_comments != $other->extracted_comments ) {
       
    88 			$this->extracted_comments .= $other->extracted_comments;
       
    89 		}
    64 		}
    90 
    65 
       
    66 		/**
       
    67 		 * PHP4 constructor.
       
    68 		 */
       
    69 		public function Translation_Entry( $args = array() ) {
       
    70 			self::__construct( $args );
       
    71 		}
       
    72 
       
    73 		/**
       
    74 		 * Generates a unique key for this entry
       
    75 		 *
       
    76 		 * @return string|bool the key or false if the entry is empty
       
    77 		 */
       
    78 		function key() {
       
    79 			if ( null === $this->singular || '' === $this->singular ) {
       
    80 				return false;
       
    81 			}
       
    82 
       
    83 			// Prepend context and EOT, like in MO files
       
    84 			$key = ! $this->context ? $this->singular : $this->context . "\4" . $this->singular;
       
    85 			// Standardize on \n line endings
       
    86 			$key = str_replace( array( "\r\n", "\r" ), "\n", $key );
       
    87 
       
    88 			return $key;
       
    89 		}
       
    90 
       
    91 		/**
       
    92 		 * @param object $other
       
    93 		 */
       
    94 		function merge_with( &$other ) {
       
    95 			$this->flags      = array_unique( array_merge( $this->flags, $other->flags ) );
       
    96 			$this->references = array_unique( array_merge( $this->references, $other->references ) );
       
    97 			if ( $this->extracted_comments != $other->extracted_comments ) {
       
    98 				$this->extracted_comments .= $other->extracted_comments;
       
    99 			}
       
   100 
       
   101 		}
    91 	}
   102 	}
    92 }
       
    93 endif;
   103 endif;