← All changes
|
inc/compatibility/multilingual/string-translator.php
+35
-1
2.12.2
→
2.12.8
View file →
| @@ -188,9 +188,9 @@ | ||
| 188 | 188 | * sides in lockstep. |
| 189 | 189 | * |
| 190 | 190 | * @param int $form_id Form post ID. |
| 191 | 191 | * @since 2.11.0 |
| 192 | - * @return array<string,string> { kind, name, title, edit_link }. | |
| 192 | + * @return array<string,string> { kind, name, title, edit_link, post_id }. | |
| 193 | 193 | */ |
| 194 | 194 | public static function form_package( int $form_id ): array { |
| 195 | 195 | $title = get_the_title( $form_id ); |
| 196 | 196 | if ( '' === $title ) { |
| @@ -204,8 +204,14 @@ | ||
| 204 | 204 | 'kind' => self::PACKAGE_KIND, |
| 205 | 205 | 'name' => (string) $form_id, |
| 206 | 206 | 'title' => $title, |
| 207 | 207 | 'edit_link' => is_string( $edit_link ) ? $edit_link : '', |
| 208 | + // Associate the package with its form post so WPML's "Translate | |
| 209 | + // Everything Automatically" queues the package alongside the post. | |
| 210 | + // NOTE: pending live-WPML confirmation of the exact key WPML reads | |
| 211 | + // for post association — `cms_id` is the documented fallback if | |
| 212 | + // `post_id` isn't consumed. Tracked in issue #2942. | |
| 213 | + 'post_id' => (string) $form_id, | |
| 208 | 214 | ]; |
| 209 | 215 | } |
| 210 | 216 | |
| 211 | 217 | /** |
| @@ -220,8 +226,20 @@ | ||
| 220 | 226 | return 'submit_button'; |
| 221 | 227 | } |
| 222 | 228 | |
| 223 | 229 | /** |
| 230 | + * Package-scoped form-title string name. The form's post title is shown as a | |
| 231 | + * heading on the form (and as the instant-form banner), so it needs to be | |
| 232 | + * registered and translated like any other user-facing string. | |
| 233 | + * | |
| 234 | + * @since 2.12.3 | |
| 235 | + * @return string | |
| 236 | + */ | |
| 237 | + public static function title_name(): string { | |
| 238 | + return 'form_title'; | |
| 239 | + } | |
| 240 | + | |
| 241 | + /** | |
| 224 | 242 | * Package-scoped confirmation-message string name. |
| 225 | 243 | * |
| 226 | 244 | * @param int $index Confirmation index. |
| 227 | 245 | * @since 2.11.0 |
| @@ -290,8 +308,24 @@ | ||
| 290 | 308 | return $value; |
| 291 | 309 | } |
| 292 | 310 | |
| 293 | 311 | return $this->dispatch_package( $form_id, self::submit_button_name(), $value ); |
| 312 | + } | |
| 313 | + | |
| 314 | + /** | |
| 315 | + * Translate a form's title (post title). | |
| 316 | + * | |
| 317 | + * @param int $form_id Form post ID. | |
| 318 | + * @param string $value Original title (used as fallback when no translation exists). | |
| 319 | + * @since 2.12.3 | |
| 320 | + * @return string Translated title, or the original when no provider/translation is available. | |
| 321 | + */ | |
| 322 | + public function translate_form_title( int $form_id, string $value ): string { | |
| 323 | + if ( '' === $value ) { | |
| 324 | + return $value; | |
| 325 | + } | |
| 326 | + | |
| 327 | + return $this->dispatch_package( $form_id, self::title_name(), $value ); | |
| 294 | 328 | } |
| 295 | 329 | |
| 296 | 330 | /** |
| 297 | 331 | * Translate a per-confirmation message. |