author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
3 |
* Contains Translation_Entry class |
|
4 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
5 |
* @version $Id: entry.php 1157 2015-11-20 04:30:11Z dd32 $ |
0 | 6 |
* @package pomo |
7 |
* @subpackage entry |
|
8 |
*/ |
|
9 |
||
9 | 10 |
if ( ! class_exists( 'Translation_Entry', false ) ) : |
0 | 11 |
/** |
19 | 12 |
* Translation_Entry class encapsulates a translatable string. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
13 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
14 |
* @since 2.8.0 |
0 | 15 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
16 |
#[AllowDynamicProperties] |
9 | 17 |
class Translation_Entry { |
18 |
||
19 |
/** |
|
19 | 20 |
* Whether the entry contains a string and its plural form, default is false. |
9 | 21 |
* |
19 | 22 |
* @var bool |
9 | 23 |
*/ |
18 | 24 |
public $is_plural = false; |
0 | 25 |
|
18 | 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(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
34 |
|
9 | 35 |
/** |
19 | 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 |
* } |
|
9 | 53 |
*/ |
19 | 54 |
public function __construct( $args = array() ) { |
16 | 55 |
// If no singular -- empty object. |
9 | 56 |
if ( ! isset( $args['singular'] ) ) { |
57 |
return; |
|
58 |
} |
|
16 | 59 |
// Get member variable values from args hash. |
9 | 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 |
} |
|
0 | 75 |
} |
76 |
||
9 | 77 |
/** |
78 |
* PHP4 constructor. |
|
16 | 79 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
80 |
* @since 2.8.0 |
16 | 81 |
* @deprecated 5.4.0 Use __construct() instead. |
82 |
* |
|
83 |
* @see Translation_Entry::__construct() |
|
9 | 84 |
*/ |
85 |
public function Translation_Entry( $args = array() ) { |
|
16 | 86 |
_deprecated_constructor( self::class, '5.4.0', static::class ); |
9 | 87 |
self::__construct( $args ); |
88 |
} |
|
89 |
||
90 |
/** |
|
19 | 91 |
* Generates a unique key for this entry. |
9 | 92 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
93 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
94 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
95 |
* @return string|false The key or false if the entry is null. |
9 | 96 |
*/ |
19 | 97 |
public function key() { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
98 |
if ( null === $this->singular ) { |
9 | 99 |
return false; |
100 |
} |
|
101 |
||
16 | 102 |
// Prepend context and EOT, like in MO files. |
9 | 103 |
$key = ! $this->context ? $this->singular : $this->context . "\4" . $this->singular; |
16 | 104 |
// Standardize on \n line endings. |
9 | 105 |
$key = str_replace( array( "\r\n", "\r" ), "\n", $key ); |
106 |
||
107 |
return $key; |
|
108 |
} |
|
109 |
||
110 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
111 |
* Merges another translation entry with the current one. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
112 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
113 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
114 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
115 |
* @param Translation_Entry $other Other translation entry. |
9 | 116 |
*/ |
19 | 117 |
public function merge_with( &$other ) { |
9 | 118 |
$this->flags = array_unique( array_merge( $this->flags, $other->flags ) ); |
119 |
$this->references = array_unique( array_merge( $this->references, $other->references ) ); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
120 |
if ( $this->extracted_comments !== $other->extracted_comments ) { |
9 | 121 |
$this->extracted_comments .= $other->extracted_comments; |
122 |
} |
|
123 |
} |
|
0 | 124 |
} |
9 | 125 |
endif; |