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 bool |
20 */ |
20 */ |
21 public $is_plural = false; |
21 public $is_plural = false; |
22 |
22 |
23 public $context = null; |
23 public $context = null; |
24 public $singular = null; |
24 public $singular = null; |
28 public $extracted_comments = ''; |
28 public $extracted_comments = ''; |
29 public $references = array(); |
29 public $references = array(); |
30 public $flags = array(); |
30 public $flags = array(); |
31 |
31 |
32 /** |
32 /** |
33 * @param array $args associative array, support following keys: |
33 * @param array $args { |
34 * - singular (string) -- the string to translate, if omitted and empty entry will be created |
34 * Arguments array, supports the following keys: |
35 * - plural (string) -- the plural form of the string, setting this will set {@link $is_plural} to true |
35 * |
36 * - translations (array) -- translations of the string and possibly -- its plural forms |
36 * @type string $singular The string to translate, if omitted an |
37 * - context (string) -- a string differentiating two equal strings used in different contexts |
37 * empty entry will be created. |
38 * - translator_comments (string) -- comments left by translators |
38 * @type string $plural The plural form of the string, setting |
39 * - extracted_comments (string) -- comments left by developers |
39 * this will set `$is_plural` to true. |
40 * - references (array) -- places in the code this strings is used, in relative_to_root_path/file.php:linenum form |
40 * @type array $translations Translations of the string and possibly |
41 * - flags (array) -- flags like php-format |
41 * its plural forms. |
|
42 * @type string $context A string differentiating two equal strings |
|
43 * used in different contexts. |
|
44 * @type string $translator_comments Comments left by translators. |
|
45 * @type string $extracted_comments Comments left by developers. |
|
46 * @type array $references Places in the code this string is used, in |
|
47 * relative_to_root_path/file.php:linenum form. |
|
48 * @type array $flags Flags like php-format. |
|
49 * } |
42 */ |
50 */ |
43 function __construct( $args = array() ) { |
51 public function __construct( $args = array() ) { |
44 // If no singular -- empty object. |
52 // If no singular -- empty object. |
45 if ( ! isset( $args['singular'] ) ) { |
53 if ( ! isset( $args['singular'] ) ) { |
46 return; |
54 return; |
47 } |
55 } |
48 // Get member variable values from args hash. |
56 // Get member variable values from args hash. |
74 _deprecated_constructor( self::class, '5.4.0', static::class ); |
82 _deprecated_constructor( self::class, '5.4.0', static::class ); |
75 self::__construct( $args ); |
83 self::__construct( $args ); |
76 } |
84 } |
77 |
85 |
78 /** |
86 /** |
79 * Generates a unique key for this entry |
87 * Generates a unique key for this entry. |
80 * |
88 * |
81 * @return string|bool the key or false if the entry is empty |
89 * @return string|false The key or false if the entry is empty. |
82 */ |
90 */ |
83 function key() { |
91 public function key() { |
84 if ( null === $this->singular || '' === $this->singular ) { |
92 if ( null === $this->singular || '' === $this->singular ) { |
85 return false; |
93 return false; |
86 } |
94 } |
87 |
95 |
88 // Prepend context and EOT, like in MO files. |
96 // Prepend context and EOT, like in MO files. |
94 } |
102 } |
95 |
103 |
96 /** |
104 /** |
97 * @param object $other |
105 * @param object $other |
98 */ |
106 */ |
99 function merge_with( &$other ) { |
107 public function merge_with( &$other ) { |
100 $this->flags = array_unique( array_merge( $this->flags, $other->flags ) ); |
108 $this->flags = array_unique( array_merge( $this->flags, $other->flags ) ); |
101 $this->references = array_unique( array_merge( $this->references, $other->references ) ); |
109 $this->references = array_unique( array_merge( $this->references, $other->references ) ); |
102 if ( $this->extracted_comments != $other->extracted_comments ) { |
110 if ( $this->extracted_comments != $other->extracted_comments ) { |
103 $this->extracted_comments .= $other->extracted_comments; |
111 $this->extracted_comments .= $other->extracted_comments; |
104 } |
112 } |