| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Contains Translation_Entry class 4 * 5 * @version $Id: entry.php 1157 2015-11-20 04:30:11Z dd32 $ 6 * @package pomo 7 * @subpackage entry 8 */ 9 10 if ( ! class_exists( 'Translation_Entry', false ) ) : 11 /** 12 * Translation_Entry class encapsulates a translatable string. 13 * 14 * @since 2.8.0 15 */ 16 #[AllowDynamicProperties] 17 class Translation_Entry { 18 19 /** 20 * Whether the entry contains a string and its plural form, default is false. 21 * 22 * @var bool 23 */ 24 public $is_plural = false; 25 26 /** 27 * The string to translate. 28 * 29 * @var string|null 30 */ 31 public $singular = null; 32 33 /** 34 * The plural form of the string. 35 * 36 * @var string|null 37 */ 38 public $plural = null; 39 40 /** 41 * Translations of the string and possibly its plural forms. 42 * 43 * Plural forms which have not been filled in are null. 44 * 45 * @var (string|null)[] 46 */ 47 public $translations = array(); 48 49 /** 50 * Context of the string, used to differentiate two equal strings used in different contexts. 51 * 52 * @var string|null 53 */ 54 public $context = null; 55 56 /** 57 * Comments left by translators. 58 * 59 * @var string 60 */ 61 public $translator_comments = ''; 62 63 /** 64 * Comments left by developers. 65 * 66 * @var string 67 */ 68 public $extracted_comments = ''; 69 70 /** 71 * Places in the code this string is used, in relative_to_root_path/file.php:linenum form. 72 * 73 * @var string[] 74 */ 75 public $references = array(); 76 77 /** 78 * Flags like php-format. 79 * 80 * @var string[] 81 */ 82 public $flags = array(); 83 84 /** 85 * Constructor. 86 * 87 * @since 2.8.0 88 * 89 * @param array $args { 90 * Optional. Array of arguments. Default empty array. 91 * 92 * @type string $singular The string to translate, if omitted an 93 * empty entry will be created. 94 * @type string $plural The plural form of the string, setting 95 * this will set `$is_plural` to true. 96 * @type (string|null)[] $translations Translations of the string and possibly 97 * its plural forms. 98 * @type string $context A string differentiating two equal strings 99 * used in different contexts. 100 * @type string $translator_comments Comments left by translators. 101 * @type string $extracted_comments Comments left by developers. 102 * @type string[] $references Places in the code this string is used, in 103 * relative_to_root_path/file.php:linenum form. 104 * @type string[] $flags Flags like php-format. 105 * } 106 */ 107 public function __construct( $args = array() ) { 108 // If no singular -- empty object. 109 if ( ! isset( $args['singular'] ) ) { 110 return; 111 } 112 // Get member variable values from args hash. 113 foreach ( $args as $varname => $value ) { 114 $this->$varname = $value; 115 } 116 if ( isset( $args['plural'] ) && $args['plural'] ) { 117 $this->is_plural = true; 118 } 119 if ( ! is_array( $this->translations ) ) { 120 $this->translations = array(); 121 } 122 if ( ! is_array( $this->references ) ) { 123 $this->references = array(); 124 } 125 if ( ! is_array( $this->flags ) ) { 126 $this->flags = array(); 127 } 128 } 129 130 /** 131 * PHP4 constructor. 132 * 133 * @since 2.8.0 134 * @deprecated 5.4.0 Use __construct() instead. 135 * 136 * @see Translation_Entry::__construct() 137 * 138 * @param array $args Optional. Array of arguments. Default empty array. 139 */ 140 public function Translation_Entry( $args = array() ) { 141 _deprecated_constructor( self::class, '5.4.0', static::class ); 142 self::__construct( $args ); 143 } 144 145 /** 146 * Generates a unique key for this entry. 147 * 148 * @since 2.8.0 149 * 150 * @return string|false The key or false if the entry is null. 151 */ 152 public function key() { 153 if ( null === $this->singular ) { 154 return false; 155 } 156 157 // Prepend context and EOT, like in MO files. 158 $key = ! $this->context ? $this->singular : $this->context . "\4" . $this->singular; 159 // Standardize on \n line endings. 160 $key = str_replace( array( "\r\n", "\r" ), "\n", $key ); 161 162 return $key; 163 } 164 165 /** 166 * Merges another translation entry with the current one. 167 * 168 * @since 2.8.0 169 * 170 * @param Translation_Entry $other Other translation entry. 171 */ 172 public function merge_with( &$other ) { 173 $this->flags = array_unique( array_merge( $this->flags, $other->flags ) ); 174 $this->references = array_unique( array_merge( $this->references, $other->references ) ); 175 if ( $this->extracted_comments !== $other->extracted_comments ) { 176 $this->extracted_comments .= $other->extracted_comments; 177 } 178 } 179 } 180 endif;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Wed Sep 2 08:20:30 2026 | Cross-referenced by PHPXref |