data( $post ); echo '
%1$s copy of “%2$s”. Visitors who open that page in %1$s see this one.', 'swiftling' ), esc_html( $copy['language'] ), esc_html( $copy['title'] ) ) /* translators: 1: language name, e.g. Deutsch, 2: title of the original. */ : sprintf( __( 'This is the separate %1$s copy of “%2$s”. Visitors who open that page in %1$s see this one once it is published.', 'swiftling' ), esc_html( $copy['language'] ), esc_html( $copy['title'] ) ), array( 'strong' => array() ) ); ?>
' . esc_html__( 'No languages chosen yet.', 'swiftling' ) . ''; printf( '%s', esc_url( $data['languagesUrl'] ), esc_html__( 'Add languages', 'swiftling' ) ); } elseif ( 'auto-draft' === $post->post_status ) { // Nothing is saved yet, and the translation starts from what is saved. echo '' . esc_html__( 'Save it first: the translation starts from what is saved here.', 'swiftling' ) . '
'; } else { ?>%s.', 'swiftling' ), esc_html( $data['source'] ) ), array( 'strong' => array() ) ); ?>
'; } /** * Returns what a language's row says, as the block editor's panel says it (rowState() in * assets/js/editor-panel.js): the state of the translation, of the separate copy, or that the * language keeps the original, showing the post as it is. * * @param array $language Language, see language(). * @return array{0: string, 1: string} State for the dot, and the words. */ private static function rowState( array $language ): array { if ( 'manual' === $language['mode'] && $language['copy'] && $language['copy']['published'] ) { return 'outdated' === $language['state'] ? array( 'outdated', __( 'Copy · original changed', 'swiftling' ) ) : array( 'reviewed', __( 'Separate copy', 'swiftling' ) ); } if ( 'manual' === $language['mode'] ) { return array( 'draft', __( 'Copy in draft', 'swiftling' ) ); } if ( 'duplicate' === $language['mode'] ) { return array( 'duplicate', __( 'Keeps the original', 'swiftling' ) ); } $labels = array( 'reviewed' => __( 'Reviewed', 'swiftling' ), 'machine' => __( 'Machine translated', 'swiftling' ), 'official' => __( 'Reviewed', 'swiftling' ), 'outdated' => __( 'Original changed', 'swiftling' ), 'partial' => __( 'Partly translated', 'swiftling' ), 'missing' => __( 'Not translated', 'swiftling' ), ); $state = isset( $labels[ $language['state'] ] ) ? $language['state'] : 'missing'; return array( $state, $labels[ $state ] ); } /** * Loads the panel script in the post editor only, not in the site or widget editor. */ public function enqueue(): void { $screen = get_current_screen(); if ( ! $screen || 'post' !== $screen->base ) { return; } wp_enqueue_script( 'swiftling-editor-panel', SWIFTLING_URL . 'assets/js/editor-panel.js', array( 'wp-api-fetch', 'wp-components', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-i18n', 'wp-plugins' ), SWIFTLING_VERSION, true ); wp_set_script_translations( 'swiftling-editor-panel', 'swiftling' ); wp_enqueue_style( 'swiftling-editor-panel', SWIFTLING_URL . 'assets/css/editor-panel.css', array(), SWIFTLING_VERSION ); wp_add_inline_script( 'swiftling-editor-panel', 'window.swiftlingEditorPanel = ' . wp_json_encode( $this->data( get_post() ) ) . ';', 'before' ); } /** * Returns what the panel shows: each language of the post, with its state, the address of its * translation editor and its separate copy, if it has one; or, for a copy, its original. * * @param \WP_Post|null $post Post being edited. * @return array