cap->edit_posts ) ) { return $type->cap->edit_posts; } } return ''; } function register_translation_bulk_actions(): void { foreach ( array_keys( translation_post_types() ) as $type ) { add_filter( 'bulk_actions-edit-' . $type, __NAMESPACE__ . '\\register_translation_bulk' ); add_filter( 'handle_bulk_actions-edit-' . $type, __NAMESPACE__ . '\\handle_translation_bulk', 10, 3 ); } } function admin_url_for( array $args = array() ): string { return add_query_arg( $args + array( 'page' => 'word-count-translator' ), admin_url( 'admin.php' ) ); } function admin_message( string $message, array $args = array(), bool $error = false, array $queued_sources = array() ): never { set_transient( 'uruvo_notice_' . get_current_user_id(), array( $message, $error, $queued_sources ), 90 ); wp_safe_redirect( admin_url_for( $args ) ); exit; } function start_form( string $task ): void { echo '
'; return; } if ( 'failed' === $job->status ) { if ( ! current_source( $job ) || unexpected_translation( $job ) ) { render_fresh_estimate_link( $job ); return; } if ( ! translation_connection_ready() ) { render_connection_required(); return; } echo 'Check the message above, then try the translation again.
'; start_form( 'retry' ); echo ''; submit_button( 'Retry translation', 'secondary' ); echo ''; return; } if ( 'stale' === $job->status ) { echo 'The source changed while the translation was running.
'; render_fresh_estimate_link( $job ); return; } if ( ! in_array( $job->status, array( 'ready', 'applying' ), true ) || ! $job->proposal ) { return; } if ( ! current_source( $job ) ) { echo 'The source changed. Review the current estimate before queueing again.
'; render_fresh_estimate_link( $job ); return; } $target = linked_target( $job ); if ( $target && unexpected_translation( $job ) ) { echo '' . esc_html__( 'A translation is already linked for this language. Start an update if you want to change it.', 'uruvo' ) . '
'; echo '' . esc_html__( 'Estimate an update', 'uruvo' ) . ''; return; } if ( $target && ! current_user_can( 'edit_post', $target->ID ) ) { echo 'The linked translation requires edit permission.
'; return; } $original = source_fields( $source ); $expected = $target ? target_review_hash( $target ) : 'new'; $proposal = review_fields( $job ); $merge = effective_content( $target, $proposal ); $choices = $target ? update_choices( $job, $target ) : array(); $labels = review_labels( $source ); $builder = page_builder( $source ); $builder_draft = $target && $builder && builder_has_pending_edits( $target ); if ( $builder_draft ) { echo '' . esc_html__( 'The linked Beaver Builder layout has unpublished changes. Publish or discard those changes before applying a layout update.', 'uruvo' ) . '
'; } echo '' . esc_html( $target ? __( 'Review the changes below. Leaving a field unchecked keeps its current translation.', 'uruvo' ) : __( 'Review the translation, then save it as a WordPress draft.', 'uruvo' ) ) . '
'; if ( $target && ! $choices ) { echo '' . esc_html__( 'The proposed copy already matches this translation.', 'uruvo' ) . '
'; render_keep_translation( $job, $expected ); return; } start_form( 'apply' ); echo ''; foreach ( $proposal as $field => $value ) { $content_merge = 'content' === $field ? $merge : null; if ( $content_merge ) { $value = $content_merge['html']; if ( $content_merge['kept'] ) { echo '' . esc_html( sprintf( 'Kept %d edited block(s). Review %d overlap(s) in the WordPress editor.', $content_merge['kept'], $content_merge['conflicts'] ) ) . '
'; } } $change = $choices[ $field ] ?? null; if ( $target && ! $change ) { continue; } if ( ! $target && '' === trim( $value ) && '' === trim( $original[ $field ] ?? '' ) ) { continue; } echo '' . esc_html__( 'Your edits will be kept unless you select this change.', 'uruvo' ) . '
'; } render_update_diff( $field, $change['before'], $change['after'] ); echo '', builder_copy( $before ) ) : ''; $value = implode( '
', builder_copy( $value ) ); } render_review_copy( __( 'Original', 'uruvo' ), $before ); render_review_copy( __( 'Proposed translation', 'uruvo' ), $value ); echo '
' . esc_html__( 'Formatting or links changed. Check the result in the page editor.', 'uruvo' ) . '
'; } } function render_review_copy( string $label, string $copy ): void { $text = review_plain_text( $copy ); printf( '%s
Worker endpoint ' . esc_html( rest_url( REST_NAMESPACE . '/' ) ) . '
Worker token ' . esc_html( $token ) . '
Updates use your shared word allowance.
'; submit_button( __( 'Save preferences', 'uruvo' ), 'secondary', 'submit', false ); echo ''; if ( hosted_settings() ) { return; } echo '' . ( $paired ? 'Worker access enabled.' : 'Generate a token for the operator who will translate your queued text.' ) . ' Text from selected public content is sent to the configured worker.
'; start_form( 'rotate' ); submit_button( $paired ? 'Rotate worker token' : 'Generate worker token', 'secondary', 'submit', false ); echo ''; if ( $paired ) { start_form( 'disconnect' ); submit_button( 'Revoke worker access', 'secondary', 'submit', false ); echo ''; } echo '