| [ Index ] |
PHP Cross Reference of BackPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Contains Translation_Entry class 4 * 5 * @version $Id: entry.php 1184 2026-03-30 00:40:06Z 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 public $context = null; 27 public $singular = null; 28 public $plural = null; 29 public $translations = array(); 30 public $translator_comments = ''; 31 public $extracted_comments = ''; 32 public $references = array(); 33 public $flags = array(); 34 35 /** 36 * @param array $args { 37 * Arguments array, supports the following keys: 38 * 39 * @type string $singular The string to translate, if omitted an 40 * empty entry will be created. 41 * @type string $plural The plural form of the string, setting 42 * this will set `$is_plural` to true. 43 * @type array $translations Translations of the string and possibly 44 * its plural forms. 45 * @type string $context A string differentiating two equal strings 46 * used in different contexts. 47 * @type string $translator_comments Comments left by translators. 48 * @type string $extracted_comments Comments left by developers. 49 * @type array $references Places in the code this string is used, in 50 * relative_to_root_path/file.php:linenum form. 51 * @type array $flags Flags like php-format. 52 * } 53 */ 54 public function __construct( $args = array() ) { 55 // If no singular -- empty object. 56 if ( ! isset( $args['singular'] ) ) { 57 return; 58 } 59 // Get member variable values from args hash. 60 foreach ( $args as $varname => $value ) { 61 $this->$varname = $value; 62 } 63 if ( isset( $args['plural'] ) && $args['plural'] ) { 64 $this->is_plural = true; 65 } 66 if ( ! is_array( $this->translations ) ) { 67 $this->translations = array(); 68 } 69 if ( ! is_array( $this->references ) ) { 70 $this->references = array(); 71 } 72 if ( ! is_array( $this->flags ) ) { 73 $this->flags = array(); 74 } 75 } 76 77 /** 78 * PHP4 constructor. 79 * 80 * @since 2.8.0 81 * @deprecated 5.4.0 Use __construct() instead. 82 * 83 * @see Translation_Entry::__construct() 84 */ 85 public function Translation_Entry( $args = array() ) { 86 if ( function_exists( '_deprecated_constructor' ) ) { 87 _deprecated_constructor( self::class, '5.4.0', static::class ); 88 } 89 self::__construct( $args ); 90 } 91 92 /** 93 * Generates a unique key for this entry. 94 * 95 * @since 2.8.0 96 * 97 * @return string|false The key or false if the entry is null. 98 */ 99 public function key() { 100 if ( null === $this->singular ) { 101 return false; 102 } 103 104 // Prepend context and EOT, like in MO files. 105 $key = ! $this->context ? $this->singular : $this->context . "\4" . $this->singular; 106 // Standardize on \n line endings. 107 $key = str_replace( array( "\r\n", "\r" ), "\n", $key ); 108 109 return $key; 110 } 111 112 /** 113 * Merges another translation entry with the current one. 114 * 115 * @since 2.8.0 116 * 117 * @param Translation_Entry $other Other translation entry. 118 */ 119 public function merge_with( &$other ) { 120 $this->flags = array_unique( array_merge( $this->flags, $other->flags ) ); 121 $this->references = array_unique( array_merge( $this->references, $other->references ) ); 122 if ( $this->extracted_comments !== $other->extracted_comments ) { 123 $this->extracted_comments .= $other->extracted_comments; 124 } 125 } 126 } 127 endif;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Apr 19 01:00:12 2026 | Cross-referenced by PHPXref 0.7.1 |