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 |
* Class for a set of entries for translation and their associated headers |
|
4 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
5 |
* @version $Id: translations.php 1157 2015-11-20 04:30:11Z dd32 $ |
0 | 6 |
* @package pomo |
7 |
* @subpackage translations |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
8 |
* @since 2.8.0 |
0 | 9 |
*/ |
10 |
||
16 | 11 |
require_once __DIR__ . '/plural-forms.php'; |
12 |
require_once __DIR__ . '/entry.php'; |
|
0 | 13 |
|
9 | 14 |
if ( ! class_exists( 'Translations', false ) ) : |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
15 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
16 |
* Translations class. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
17 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
18 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
19 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
20 |
#[AllowDynamicProperties] |
9 | 21 |
class Translations { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
22 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
23 |
* List of translation entries. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
24 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
25 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
26 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
27 |
* @var Translation_Entry[] |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
28 |
*/ |
18 | 29 |
public $entries = array(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
30 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
31 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
32 |
* List of translation headers. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
33 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
34 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
35 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
36 |
* @var array<string, string> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
37 |
*/ |
18 | 38 |
public $headers = array(); |
0 | 39 |
|
9 | 40 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
41 |
* Adds an entry to the PO structure. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
42 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
43 |
* @since 2.8.0 |
9 | 44 |
* |
45 |
* @param array|Translation_Entry $entry |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
46 |
* @return bool True on success, false if the entry doesn't have a key. |
9 | 47 |
*/ |
19 | 48 |
public function add_entry( $entry ) { |
9 | 49 |
if ( is_array( $entry ) ) { |
50 |
$entry = new Translation_Entry( $entry ); |
|
51 |
} |
|
52 |
$key = $entry->key(); |
|
53 |
if ( false === $key ) { |
|
54 |
return false; |
|
55 |
} |
|
56 |
$this->entries[ $key ] = &$entry; |
|
57 |
return true; |
|
0 | 58 |
} |
9 | 59 |
|
60 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
61 |
* Adds or merges an entry to the PO structure. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
62 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
63 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
64 |
* |
9 | 65 |
* @param array|Translation_Entry $entry |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
66 |
* @return bool True on success, false if the entry doesn't have a key. |
9 | 67 |
*/ |
19 | 68 |
public function add_entry_or_merge( $entry ) { |
9 | 69 |
if ( is_array( $entry ) ) { |
70 |
$entry = new Translation_Entry( $entry ); |
|
71 |
} |
|
72 |
$key = $entry->key(); |
|
73 |
if ( false === $key ) { |
|
74 |
return false; |
|
75 |
} |
|
76 |
if ( isset( $this->entries[ $key ] ) ) { |
|
77 |
$this->entries[ $key ]->merge_with( $entry ); |
|
78 |
} else { |
|
79 |
$this->entries[ $key ] = &$entry; |
|
80 |
} |
|
81 |
return true; |
|
82 |
} |
|
0 | 83 |
|
9 | 84 |
/** |
85 |
* Sets $header PO header to $value |
|
86 |
* |
|
87 |
* If the header already exists, it will be overwritten |
|
88 |
* |
|
89 |
* TODO: this should be out of this class, it is gettext specific |
|
90 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
91 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
92 |
* |
9 | 93 |
* @param string $header header name, without trailing : |
94 |
* @param string $value header value, without trailing \n |
|
95 |
*/ |
|
19 | 96 |
public function set_header( $header, $value ) { |
9 | 97 |
$this->headers[ $header ] = $value; |
98 |
} |
|
0 | 99 |
|
9 | 100 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
101 |
* Sets translation headers. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
102 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
103 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
104 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
105 |
* @param array $headers Associative array of headers. |
9 | 106 |
*/ |
19 | 107 |
public function set_headers( $headers ) { |
9 | 108 |
foreach ( $headers as $header => $value ) { |
109 |
$this->set_header( $header, $value ); |
|
110 |
} |
|
0 | 111 |
} |
9 | 112 |
|
113 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
114 |
* Returns a given translation header. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
115 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
116 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
117 |
* |
9 | 118 |
* @param string $header |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
119 |
* @return string|false Header if it exists, false otherwise. |
9 | 120 |
*/ |
19 | 121 |
public function get_header( $header ) { |
9 | 122 |
return isset( $this->headers[ $header ] ) ? $this->headers[ $header ] : false; |
123 |
} |
|
124 |
||
125 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
126 |
* Returns a given translation entry. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
127 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
128 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
129 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
130 |
* @param Translation_Entry $entry Translation entry. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
131 |
* @return Translation_Entry|false Translation entry if it exists, false otherwise. |
9 | 132 |
*/ |
19 | 133 |
public function translate_entry( &$entry ) { |
9 | 134 |
$key = $entry->key(); |
135 |
return isset( $this->entries[ $key ] ) ? $this->entries[ $key ] : false; |
|
136 |
} |
|
0 | 137 |
|
9 | 138 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
139 |
* Translates a singular string. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
140 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
141 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
142 |
* |
9 | 143 |
* @param string $singular |
144 |
* @param string $context |
|
145 |
* @return string |
|
146 |
*/ |
|
19 | 147 |
public function translate( $singular, $context = null ) { |
9 | 148 |
$entry = new Translation_Entry( |
149 |
array( |
|
150 |
'singular' => $singular, |
|
151 |
'context' => $context, |
|
152 |
) |
|
153 |
); |
|
154 |
$translated = $this->translate_entry( $entry ); |
|
155 |
return ( $translated && ! empty( $translated->translations ) ) ? $translated->translations[0] : $singular; |
|
156 |
} |
|
0 | 157 |
|
9 | 158 |
/** |
159 |
* Given the number of items, returns the 0-based index of the plural form to use |
|
160 |
* |
|
161 |
* Here, in the base Translations class, the common logic for English is implemented: |
|
162 |
* 0 if there is one element, 1 otherwise |
|
163 |
* |
|
16 | 164 |
* This function should be overridden by the subclasses. For example MO/PO can derive the logic |
9 | 165 |
* from their headers. |
166 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
167 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
168 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
169 |
* @param int $count Number of items. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
170 |
* @return int Plural form to use. |
9 | 171 |
*/ |
19 | 172 |
public function select_plural_form( $count ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
173 |
return 1 === (int) $count ? 0 : 1; |
9 | 174 |
} |
0 | 175 |
|
9 | 176 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
177 |
* Returns the plural forms count. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
178 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
179 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
180 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
181 |
* @return int Plural forms count. |
9 | 182 |
*/ |
19 | 183 |
public function get_plural_forms_count() { |
9 | 184 |
return 2; |
185 |
} |
|
0 | 186 |
|
9 | 187 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
188 |
* Translates a plural string. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
189 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
190 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
191 |
* |
9 | 192 |
* @param string $singular |
193 |
* @param string $plural |
|
194 |
* @param int $count |
|
195 |
* @param string $context |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
196 |
* @return string |
9 | 197 |
*/ |
19 | 198 |
public function translate_plural( $singular, $plural, $count, $context = null ) { |
9 | 199 |
$entry = new Translation_Entry( |
200 |
array( |
|
201 |
'singular' => $singular, |
|
202 |
'plural' => $plural, |
|
203 |
'context' => $context, |
|
204 |
) |
|
205 |
); |
|
206 |
$translated = $this->translate_entry( $entry ); |
|
207 |
$index = $this->select_plural_form( $count ); |
|
208 |
$total_plural_forms = $this->get_plural_forms_count(); |
|
209 |
if ( $translated && 0 <= $index && $index < $total_plural_forms && |
|
210 |
is_array( $translated->translations ) && |
|
211 |
isset( $translated->translations[ $index ] ) ) { |
|
212 |
return $translated->translations[ $index ]; |
|
213 |
} else { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
214 |
return 1 === (int) $count ? $singular : $plural; |
9 | 215 |
} |
216 |
} |
|
0 | 217 |
|
9 | 218 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
219 |
* Merges other translations into the current one. |
9 | 220 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
221 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
222 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
223 |
* @param Translations $other Another Translation object, whose translations will be merged in this one (passed by reference). |
9 | 224 |
*/ |
19 | 225 |
public function merge_with( &$other ) { |
9 | 226 |
foreach ( $other->entries as $entry ) { |
227 |
$this->entries[ $entry->key() ] = $entry; |
|
228 |
} |
|
229 |
} |
|
0 | 230 |
|
9 | 231 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
232 |
* Merges originals with existing entries. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
233 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
234 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
235 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
236 |
* @param Translations $other |
9 | 237 |
*/ |
19 | 238 |
public function merge_originals_with( &$other ) { |
9 | 239 |
foreach ( $other->entries as $entry ) { |
240 |
if ( ! isset( $this->entries[ $entry->key() ] ) ) { |
|
241 |
$this->entries[ $entry->key() ] = $entry; |
|
242 |
} else { |
|
243 |
$this->entries[ $entry->key() ]->merge_with( $entry ); |
|
244 |
} |
|
245 |
} |
|
0 | 246 |
} |
247 |
} |
|
248 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
249 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
250 |
* Gettext_Translations class. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
251 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
252 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
253 |
*/ |
9 | 254 |
class Gettext_Translations extends Translations { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
255 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
256 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
257 |
* Number of plural forms. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
258 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
259 |
* @var int |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
260 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
261 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
262 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
263 |
public $_nplurals; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
264 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
265 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
266 |
* Callback to retrieve the plural form. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
267 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
268 |
* @var callable |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
269 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
270 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
271 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
272 |
public $_gettext_select_plural_form; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
273 |
|
9 | 274 |
/** |
275 |
* The gettext implementation of select_plural_form. |
|
276 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
277 |
* It lives in this class, because there are more than one descendant, which will use it and |
9 | 278 |
* they can't share it effectively. |
279 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
280 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
281 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
282 |
* @param int $count Plural forms count. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
283 |
* @return int Plural form to use. |
9 | 284 |
*/ |
19 | 285 |
public function gettext_select_plural_form( $count ) { |
9 | 286 |
if ( ! isset( $this->_gettext_select_plural_form ) || is_null( $this->_gettext_select_plural_form ) ) { |
287 |
list( $nplurals, $expression ) = $this->nplurals_and_expression_from_header( $this->get_header( 'Plural-Forms' ) ); |
|
288 |
$this->_nplurals = $nplurals; |
|
289 |
$this->_gettext_select_plural_form = $this->make_plural_form_function( $nplurals, $expression ); |
|
290 |
} |
|
291 |
return call_user_func( $this->_gettext_select_plural_form, $count ); |
|
0 | 292 |
} |
293 |
||
9 | 294 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
295 |
* Returns the nplurals and plural forms expression from the Plural-Forms header. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
296 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
297 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
298 |
* |
9 | 299 |
* @param string $header |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
300 |
* @return array{0: int, 1: string} |
9 | 301 |
*/ |
19 | 302 |
public function nplurals_and_expression_from_header( $header ) { |
9 | 303 |
if ( preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s+plural\s*=\s*(.+)$/', $header, $matches ) ) { |
304 |
$nplurals = (int) $matches[1]; |
|
305 |
$expression = trim( $matches[2] ); |
|
306 |
return array( $nplurals, $expression ); |
|
307 |
} else { |
|
308 |
return array( 2, 'n != 1' ); |
|
309 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
310 |
} |
0 | 311 |
|
9 | 312 |
/** |
313 |
* Makes a function, which will return the right translation index, according to the |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
314 |
* plural forms header. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
315 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
316 |
* @since 2.8.0 |
9 | 317 |
* |
318 |
* @param int $nplurals |
|
319 |
* @param string $expression |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
320 |
* @return callable |
9 | 321 |
*/ |
19 | 322 |
public function make_plural_form_function( $nplurals, $expression ) { |
9 | 323 |
try { |
324 |
$handler = new Plural_Forms( rtrim( $expression, ';' ) ); |
|
325 |
return array( $handler, 'get' ); |
|
326 |
} catch ( Exception $e ) { |
|
327 |
// Fall back to default plural-form function. |
|
328 |
return $this->make_plural_form_function( 2, 'n != 1' ); |
|
0 | 329 |
} |
330 |
} |
|
331 |
||
9 | 332 |
/** |
333 |
* Adds parentheses to the inner parts of ternary operators in |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
334 |
* plural expressions, because PHP evaluates ternary operators from left to right |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
335 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
336 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
337 |
* @deprecated 6.5.0 Use the Plural_Forms class instead. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
338 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
339 |
* @see Plural_Forms |
9 | 340 |
* |
341 |
* @param string $expression the expression without parentheses |
|
342 |
* @return string the expression with parentheses added |
|
343 |
*/ |
|
19 | 344 |
public function parenthesize_plural_exression( $expression ) { |
9 | 345 |
$expression .= ';'; |
346 |
$res = ''; |
|
347 |
$depth = 0; |
|
348 |
for ( $i = 0; $i < strlen( $expression ); ++$i ) { |
|
349 |
$char = $expression[ $i ]; |
|
350 |
switch ( $char ) { |
|
351 |
case '?': |
|
352 |
$res .= ' ? ('; |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
353 |
++$depth; |
9 | 354 |
break; |
355 |
case ':': |
|
356 |
$res .= ') : ('; |
|
357 |
break; |
|
358 |
case ';': |
|
359 |
$res .= str_repeat( ')', $depth ) . ';'; |
|
360 |
$depth = 0; |
|
361 |
break; |
|
362 |
default: |
|
363 |
$res .= $char; |
|
364 |
} |
|
365 |
} |
|
366 |
return rtrim( $res, ';' ); |
|
0 | 367 |
} |
368 |
||
9 | 369 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
370 |
* Prepare translation headers. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
371 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
372 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
373 |
* |
9 | 374 |
* @param string $translation |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
375 |
* @return array<string, string> Translation headers |
9 | 376 |
*/ |
19 | 377 |
public function make_headers( $translation ) { |
9 | 378 |
$headers = array(); |
16 | 379 |
// Sometimes \n's are used instead of real new lines. |
9 | 380 |
$translation = str_replace( '\n', "\n", $translation ); |
381 |
$lines = explode( "\n", $translation ); |
|
382 |
foreach ( $lines as $line ) { |
|
383 |
$parts = explode( ':', $line, 2 ); |
|
384 |
if ( ! isset( $parts[1] ) ) { |
|
385 |
continue; |
|
386 |
} |
|
387 |
$headers[ trim( $parts[0] ) ] = trim( $parts[1] ); |
|
388 |
} |
|
389 |
return $headers; |
|
390 |
} |
|
391 |
||
392 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
393 |
* Sets translation headers. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
394 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
395 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
396 |
* |
9 | 397 |
* @param string $header |
398 |
* @param string $value |
|
399 |
*/ |
|
19 | 400 |
public function set_header( $header, $value ) { |
9 | 401 |
parent::set_header( $header, $value ); |
16 | 402 |
if ( 'Plural-Forms' === $header ) { |
9 | 403 |
list( $nplurals, $expression ) = $this->nplurals_and_expression_from_header( $this->get_header( 'Plural-Forms' ) ); |
404 |
$this->_nplurals = $nplurals; |
|
405 |
$this->_gettext_select_plural_form = $this->make_plural_form_function( $nplurals, $expression ); |
|
406 |
} |
|
0 | 407 |
} |
408 |
} |
|
409 |
endif; |
|
410 |
||
9 | 411 |
if ( ! class_exists( 'NOOP_Translations', false ) ) : |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
413 |
* Provides the same interface as Translations, but doesn't do anything. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
414 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
415 |
* @since 2.8.0 |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
*/ |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
417 |
#[AllowDynamicProperties] |
9 | 418 |
class NOOP_Translations { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
419 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
420 |
* List of translation entries. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
421 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
422 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
423 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
424 |
* @var Translation_Entry[] |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
425 |
*/ |
18 | 426 |
public $entries = array(); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
427 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
428 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
429 |
* List of translation headers. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
430 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
431 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
432 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
433 |
* @var array<string, string> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
434 |
*/ |
18 | 435 |
public $headers = array(); |
9 | 436 |
|
19 | 437 |
public function add_entry( $entry ) { |
9 | 438 |
return true; |
439 |
} |
|
440 |
||
441 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
442 |
* Sets a translation header. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
443 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
444 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
445 |
* |
9 | 446 |
* @param string $header |
447 |
* @param string $value |
|
448 |
*/ |
|
19 | 449 |
public function set_header( $header, $value ) { |
9 | 450 |
} |
451 |
||
452 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
453 |
* Sets translation headers. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
454 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
455 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
456 |
* |
9 | 457 |
* @param array $headers |
458 |
*/ |
|
19 | 459 |
public function set_headers( $headers ) { |
9 | 460 |
} |
461 |
||
462 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
463 |
* Returns a translation header. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
464 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
465 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
466 |
* |
9 | 467 |
* @param string $header |
468 |
* @return false |
|
469 |
*/ |
|
19 | 470 |
public function get_header( $header ) { |
9 | 471 |
return false; |
472 |
} |
|
473 |
||
474 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
475 |
* Returns a given translation entry. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
476 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
477 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
478 |
* |
9 | 479 |
* @param Translation_Entry $entry |
480 |
* @return false |
|
481 |
*/ |
|
19 | 482 |
public function translate_entry( &$entry ) { |
9 | 483 |
return false; |
484 |
} |
|
0 | 485 |
|
9 | 486 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
487 |
* Translates a singular string. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
488 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
489 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
490 |
* |
9 | 491 |
* @param string $singular |
492 |
* @param string $context |
|
493 |
*/ |
|
19 | 494 |
public function translate( $singular, $context = null ) { |
9 | 495 |
return $singular; |
496 |
} |
|
497 |
||
498 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
499 |
* Returns the plural form to use. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
500 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
501 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
502 |
* |
9 | 503 |
* @param int $count |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
504 |
* @return int |
9 | 505 |
*/ |
19 | 506 |
public function select_plural_form( $count ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
507 |
return 1 === (int) $count ? 0 : 1; |
9 | 508 |
} |
509 |
||
510 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
511 |
* Returns the plural forms count. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
512 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
513 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
514 |
* |
9 | 515 |
* @return int |
516 |
*/ |
|
19 | 517 |
public function get_plural_forms_count() { |
9 | 518 |
return 2; |
519 |
} |
|
520 |
||
521 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
522 |
* Translates a plural string. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
523 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
524 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
525 |
* |
9 | 526 |
* @param string $singular |
527 |
* @param string $plural |
|
528 |
* @param int $count |
|
529 |
* @param string $context |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
530 |
* @return string |
9 | 531 |
*/ |
19 | 532 |
public function translate_plural( $singular, $plural, $count, $context = null ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
533 |
return 1 === (int) $count ? $singular : $plural; |
9 | 534 |
} |
535 |
||
536 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
537 |
* Merges other translations into the current one. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
538 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
539 |
* @since 2.8.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
540 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
541 |
* @param Translations $other |
9 | 542 |
*/ |
19 | 543 |
public function merge_with( &$other ) { |
9 | 544 |
} |
0 | 545 |
} |
546 |
endif; |