From 019edad345b5f10fbab79db3f3a2d0842e09214d Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Tue, 30 Aug 2022 15:00:51 +1000 Subject: [PATCH 01/12] Improve translatability of text. --- assets/js/gutenberg-plugin.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/assets/js/gutenberg-plugin.js b/assets/js/gutenberg-plugin.js index 8f421f65f..4624e0534 100644 --- a/assets/js/gutenberg-plugin.js +++ b/assets/js/gutenberg-plugin.js @@ -3,7 +3,7 @@ import { pluginIcon } from './components/plugin-icon'; import { Icon } from '@wordpress/components'; import { select, useSelect } from '@wordpress/data'; import { PluginDocumentSettingPanel } from '@wordpress/edit-post'; -import { __, sprintf } from '@wordpress/i18n'; +import { __, _n, _x, sprintf } from '@wordpress/i18n'; import { registerPlugin } from '@wordpress/plugins'; const { document, dtGutenberg, MouseEvent } = window; @@ -64,7 +64,12 @@ const RenderShowAdminBar = () => { { sprintf( /** translators: 1: Post type or generic term content. */ __( 'Distribute %1$s', 'distributor' ), - dtGutenberg.postTypeSingular || 'Content' + dtGutenberg.postTypeSingular || + _x( + 'content', + 'generic term for post content', + 'distributor' + ) ) } @@ -110,9 +115,13 @@ const RenderDistributedTo = () => { { sprintf( /** translators: 1: Number of connections content distributed to. */ - __( 'Distributed to %1$s connection%2$s.', 'distributor' ), - dtGutenberg.syndicationCount, - '1' === dtGutenberg.syndicationCount ? '' : 's' + _n( + 'Distributed to %1$s connection.', + 'Distributed to %1$s connections.', + dtGutenberg.syndicationCount * 1, // Syndication count is a string, so we need to convert it to a number. + 'distributor' + ), + dtGutenberg.syndicationCount ) } ); @@ -124,8 +133,11 @@ const RenderDistributedTo = () => { const RenderDistributedFrom = () => { return ( - { __( 'Distributed on: ', 'distributor' ) } - { dtGutenberg.syndicationTime } + { sprintf( + /** translators: 1: Syndication date and time. */ + __( 'Distributed on: %1$s', 'distributor' ), + dtGutenberg.syndicationTime + ) } ); }; From acdb1e05bf752161c405af1eb316d162c776a2db Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Tue, 30 Aug 2022 15:47:07 +1000 Subject: [PATCH 02/12] Improve translatability of text. --- assets/js/gutenberg-syndicated-post.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/assets/js/gutenberg-syndicated-post.js b/assets/js/gutenberg-syndicated-post.js index c307368ca..20757b7fc 100644 --- a/assets/js/gutenberg-syndicated-post.js +++ b/assets/js/gutenberg-syndicated-post.js @@ -21,16 +21,17 @@ if ( ); } else if ( ! parseInt( dtGutenberg.unlinked ) ) { message = sprintf( - /** translators: 1) Source of content. */ + /** translators: 1) Source of content, 2) Distributor post type singular name. */ __( - 'Distributed from %s. The original will update this version unless you', + 'Distributed from %1$s. This %2$s is linked to the original. Edits to the original will update this version.', 'distributor' ), - dtGutenberg.originalLocationName + dtGutenberg.originalLocationName, + dtGutenberg.postTypeSingular ); actions.push( { - label: __( 'unlink from original.', 'distributor' ), + label: __( 'Unlink from original.', 'distributor' ), url: dtGutenberg.unlinkNonceUrl, } ); @@ -42,7 +43,7 @@ if ( message = sprintf( /** translators: 1) Source of content, 2) Distributor post type singular name. */ __( - 'Originally distributed from %1$s. This %2$s has been unlinked from the original. However, you can always', + 'Originally distributed from %1$s. This %2$s has been unlinked from the original. Edits to the original will not update this version.', 'distributor' ), dtGutenberg.originalLocationName, @@ -50,7 +51,7 @@ if ( ); actions.push( { - label: __( 'restore it.', 'distributor' ), + label: __( 'Relink to original.', 'distributor' ), url: dtGutenberg.linkNonceUrl, } ); From 99096c2487462b19d9b9e2254a2e9151eff87f03 Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Wed, 31 Aug 2022 15:32:47 +1000 Subject: [PATCH 03/12] =?UTF-8?q?Fix=20translation=20comments:=20they?= =?UTF-8?q?=E2=80=99re=20not=20docblocks.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/js/gutenberg-syndicated-post.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/assets/js/gutenberg-syndicated-post.js b/assets/js/gutenberg-syndicated-post.js index 20757b7fc..aa7fb20b6 100644 --- a/assets/js/gutenberg-syndicated-post.js +++ b/assets/js/gutenberg-syndicated-post.js @@ -12,7 +12,7 @@ if ( if ( parseInt( dtGutenberg.originalDelete ) ) { message = sprintf( - /** translators: 1) Distributor post type singular name, 2) Source of content. */ + /* translators: 1) Distributor post type singular name, 2) Source of content. */ __( 'This %1$s was distributed from %2$s. However, the original has been deleted.' ), @@ -21,7 +21,7 @@ if ( ); } else if ( ! parseInt( dtGutenberg.unlinked ) ) { message = sprintf( - /** translators: 1) Source of content, 2) Distributor post type singular name. */ + /* translators: 1) Source of content, 2) Distributor post type singular name. */ __( 'Distributed from %1$s. This %2$s is linked to the original. Edits to the original will update this version.', 'distributor' @@ -41,7 +41,7 @@ if ( } ); } else { message = sprintf( - /** translators: 1) Source of content, 2) Distributor post type singular name. */ + /* translators: 1) Source of content, 2) Distributor post type singular name. */ __( 'Originally distributed from %1$s. This %2$s has been unlinked from the original. Edits to the original will not update this version.', 'distributor' From 25dcfafc622f37fd2f0fa2c5669ef628cd04debd Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Wed, 31 Aug 2022 15:33:09 +1000 Subject: [PATCH 04/12] Unify classic editor strings with block editors strings. --- includes/syndicated-post-ui.php | 45 +++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/includes/syndicated-post-ui.php b/includes/syndicated-post-ui.php index 642eb6eed..f01521602 100644 --- a/includes/syndicated-post-ui.php +++ b/includes/syndicated-post-ui.php @@ -422,7 +422,7 @@ function syndicated_message( $post ) { $post_type_object = get_post_type_object( $post->post_type ); - $post_url = get_post_meta( $post->ID, 'dt_original_post_url', true ); + $original_post_url = get_post_meta( $post->ID, 'dt_original_post_url', true ); $original_site_name = get_post_meta( $post->ID, 'dt_original_site_name', true ); if ( ! empty( $original_blog_id ) && is_multisite() ) { @@ -445,30 +445,53 @@ function syndicated_message( $post ) {

%3$s. However, the original has been deleted.', 'distributor' ), esc_html( strtolower( $post_type_singular ) ), esc_url( $post_url ), esc_html( $original_location_name ) ) ); + printf( + /* translators: 1) Distributor post type singular name, 2) Source of content. */ + esc_html__( 'This %1$s was distributed from %2$s. However, the original has been deleted.', 'distributor' ), + esc_html( strtolower( $post_type_singular ) ), + esc_html( $original_location_name ) + ); ?>

%2$s.', 'distributor' ), esc_url( $post_url ), esc_html( $original_location_name ) ) ); + printf( + /* translators: 1) Source of content, 2) Distributor post type singular name. */ + esc_html__( 'Distributed from %1$s. This %2$s is linked to the original. Edits to the original will update this version.', 'distributor' ), + esc_html( $original_location_name ), + esc_html( strtolower( $post_type_singular ) ) + ); ?> ID ) ) : + $unlink_url = wp_nonce_url( add_query_arg( 'action', 'unlink', admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) ), "unlink-post_{$post->ID}" ); ?> - - unlink from the original.', 'distributor' ), esc_html( strtolower( $post_type_singular ) ), wp_nonce_url( add_query_arg( 'action', 'unlink', admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) ), "unlink-post_{$post->ID}" ) ) ); ?> +

+

+ +

- - %1$s.', 'distributor' ), esc_url( $post_url ), esc_html( $original_location_name ) ) ); ?> - - restore it.", 'distributor' ), esc_html( strtolower( $post_type_singular ) ), wp_nonce_url( add_query_arg( 'action', 'link', admin_url( sprintf( $post_type_object->_edit_link, $post->ID ) ) ), "link-post_{$post->ID}" ) ) ); ?> + _edit_link, $post->ID ) ) ), "link-post_{$post->ID}" ); + ?> +

+

+ +

From cfd4838847f24f5b7a92156df0aa89b6ad8aa1bb Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Wed, 31 Aug 2022 15:33:55 +1000 Subject: [PATCH 05/12] =?UTF-8?q?Fix=20translation=20comments:=20they?= =?UTF-8?q?=E2=80=99re=20not=20docblocks.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/js/gutenberg-plugin.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/assets/js/gutenberg-plugin.js b/assets/js/gutenberg-plugin.js index 4624e0534..9d4849479 100644 --- a/assets/js/gutenberg-plugin.js +++ b/assets/js/gutenberg-plugin.js @@ -62,7 +62,7 @@ const RenderShowAdminBar = () => { } } > { sprintf( - /** translators: 1: Post type or generic term content. */ + /* translators: 1: Post type or generic term content. */ __( 'Distribute %1$s', 'distributor' ), dtGutenberg.postTypeSingular || _x( @@ -114,7 +114,7 @@ const RenderDistributedTo = () => { return ( { sprintf( - /** translators: 1: Number of connections content distributed to. */ + /* translators: 1: Number of connections content distributed to. */ _n( 'Distributed to %1$s connection.', 'Distributed to %1$s connections.', @@ -134,7 +134,7 @@ const RenderDistributedFrom = () => { return ( { sprintf( - /** translators: 1: Syndication date and time. */ + /* translators: 1: Syndication date and time. */ __( 'Distributed on: %1$s', 'distributor' ), dtGutenberg.syndicationTime ) } From 446713cb596ff72651cd1330f7f0043bd67e12b4 Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Thu, 1 Sep 2022 13:42:37 +1000 Subject: [PATCH 06/12] Remove concatenation to improve translatability. --- .../WordPressDotcomOauth2Authentication.php | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/includes/classes/Authentications/WordPressDotcomOauth2Authentication.php b/includes/classes/Authentications/WordPressDotcomOauth2Authentication.php index 4098af8fc..5407ae733 100644 --- a/includes/classes/Authentications/WordPressDotcomOauth2Authentication.php +++ b/includes/classes/Authentications/WordPressDotcomOauth2Authentication.php @@ -107,10 +107,27 @@ public static function credentials_form( $args = array() ) { ) { ?>
-

- .

-


-

+

+ create an application with the WordPress.com applications manager.', 'distributor' ), + esc_url( 'https://developer.wordpress.com/apps/' ) + ) + ); + ?> +

+ +

+ ' . esc_url( admin_url( 'post.php' ) ) . '' + ); + ?> +

Date: Thu, 1 Sep 2022 13:43:07 +1000 Subject: [PATCH 07/12] Ensure all errors include a period to reduce strings. --- .../WordPressExternalConnection.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/includes/classes/ExternalConnections/WordPressExternalConnection.php b/includes/classes/ExternalConnections/WordPressExternalConnection.php index 11f5dd8b8..1f21f1773 100644 --- a/includes/classes/ExternalConnections/WordPressExternalConnection.php +++ b/includes/classes/ExternalConnections/WordPressExternalConnection.php @@ -211,19 +211,19 @@ public function remote_get( $args = array() ) { $types_body = wp_remote_retrieve_body( $types_response ); if ( empty( $types_body ) ) { - return new \WP_Error( 'no-response-body', esc_html__( 'Response body is empty', 'distributor' ) ); + return new \WP_Error( 'no-response-body', esc_html__( 'Response body is empty.', 'distributor' ) ); } $types_body_array = json_decode( $types_body, true ); if ( empty( $types_body_array ) || empty( $types_body_array[ $post_type ] ) ) { - return new \WP_Error( 'no-pull-post-type', esc_html__( 'Could not determine remote post type endpoint', 'distributor' ) ); + return new \WP_Error( 'no-pull-post-type', esc_html__( 'Could not determine remote post type endpoint.', 'distributor' ) ); } $types_urls[ $post_type ] = $this->parse_type_items_link( $types_body_array[ $post_type ] ); if ( empty( $types_urls[ $post_type ] ) ) { - return new \WP_Error( 'no-pull-post-type', esc_html__( 'Could not determine remote post type endpoint', 'distributor' ) ); + return new \WP_Error( 'no-pull-post-type', esc_html__( 'Could not determine remote post type endpoint.', 'distributor' ) ); } } @@ -332,7 +332,7 @@ public function remote_get( $args = array() ) { $posts_body = wp_remote_retrieve_body( $posts_response ); if ( empty( $posts_body ) ) { - return new \WP_Error( 'no-response-body', esc_html__( 'Response body is empty', 'distributor' ) ); + return new \WP_Error( 'no-response-body', esc_html__( 'Response body is empty.', 'distributor' ) ); } $posts = json_decode( $posts_body, true ); @@ -377,7 +377,7 @@ public function remote_get( $args = array() ) { */ public function remote_post( $url = '', $args = array() ) { if ( ! $url ) { - return new \WP_Error( 'endpoint-error', esc_html__( 'Endpoint URL must be set', 'distributor' ) ); + return new \WP_Error( 'endpoint-error', esc_html__( 'Endpoint URL must be set.', 'distributor' ) ); } /** @@ -440,7 +440,7 @@ public function remote_post( $url = '', $args = array() ) { $response_headers = wp_remote_retrieve_headers( $request ); if ( empty( $posts_body ) ) { - return new \WP_Error( 'no-response-body', esc_html__( 'Response body is empty', 'distributor' ) ); + return new \WP_Error( 'no-response-body', esc_html__( 'Response body is empty.', 'distributor' ) ); } $posts = json_decode( $posts_body, true ); @@ -602,7 +602,7 @@ public function pull( $items ) { */ public function push( $post_id, $args = array() ) { if ( empty( $post_id ) ) { - return new \WP_Error( 'no-push-post-id', esc_html__( 'Post id required to push', 'distributor' ) ); + return new \WP_Error( 'no-push-post-id', esc_html__( 'Post ID required to push.', 'distributor' ) ); } $post = get_post( $post_id ); @@ -629,7 +629,7 @@ public function push( $post_id, $args = array() ) { $body = wp_remote_retrieve_body( $response ); if ( empty( $body ) ) { - return new \WP_Error( 'no-response-body', esc_html__( 'Response body is empty', 'distributor' ) ); + return new \WP_Error( 'no-response-body', esc_html__( 'Response body is empty.', 'distributor' ) ); } $body_array = json_decode( $body, true ); @@ -637,7 +637,7 @@ public function push( $post_id, $args = array() ) { $type_url = $this->parse_type_items_link( $body_array[ $post_type ] ); if ( empty( $type_url ) ) { - return new \WP_Error( 'no-push-post-type', esc_html__( 'Could not determine remote post type endpoint', 'distributor' ) ); + return new \WP_Error( 'no-push-post-type', esc_html__( 'Could not determine remote post type endpoint.', 'distributor' ) ); } $signature = \Distributor\Subscriptions\generate_signature(); @@ -733,13 +733,13 @@ public function push( $post_id, $args = array() ) { $body = wp_remote_retrieve_body( $response ); if ( empty( $body ) ) { - return new \WP_Error( 'no-response-body', esc_html__( 'Response body is empty', 'distributor' ) ); + return new \WP_Error( 'no-response-body', esc_html__( 'Response body is empty.', 'distributor' ) ); } $body_array = json_decode( $body, true ); if ( empty( $body_array['id'] ) ) { - return new \WP_Error( 'no-push-post-remote-id', esc_html__( 'Could not determine remote post id.', 'distributor' ) ); + return new \WP_Error( 'no-push-post-remote-id', esc_html__( 'Could not determine remote post ID.', 'distributor' ) ); } $response_headers = wp_remote_retrieve_headers( $response ); @@ -787,7 +787,7 @@ public function get_post_types() { $types_body = wp_remote_retrieve_body( $types_response ); if ( empty( $types_body ) ) { - return new \WP_Error( 'no-response-body', esc_html__( 'Response body is empty', 'distributor' ) ); + return new \WP_Error( 'no-response-body', esc_html__( 'Response body is empty.', 'distributor' ) ); } $types_body_array = json_decode( $types_body, true ); From 996c78743be9942b099b2a922729e8f861541f12 Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Thu, 1 Sep 2022 13:43:38 +1000 Subject: [PATCH 08/12] Reduce strings to aid translators. --- includes/classes/PullListTable.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/classes/PullListTable.php b/includes/classes/PullListTable.php index c007ff77f..531d6f408 100644 --- a/includes/classes/PullListTable.php +++ b/includes/classes/PullListTable.php @@ -321,14 +321,14 @@ public function column_name( $item ) { $disable = true; } else { /** - * Filter the default value of the 'Pull in as draft' option in the pull ui + * Filter the default value of the 'Pull as draft' option in the pull ui * * @hook dt_pull_as_draft * - * @param {bool} $as_draft Whether the 'Pull in as draft' option should be checked. + * @param {bool} $as_draft Whether the 'Pull as draft' option should be checked. * @param {object} $connection The connection being used to pull from. * - * @return {bool} Whether the 'Pull in as draft' option should be checked. + * @return {bool} Whether the 'Pull as draft' option should be checked. */ $as_draft = apply_filters( 'dt_pull_as_draft', true, $connection_now ); @@ -639,7 +639,7 @@ public function extra_tablenav( $which ) { ?>
From 7ef40d3e5ea4f658ffabadd78c188a2fc63f94d1 Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Thu, 1 Sep 2022 13:44:22 +1000 Subject: [PATCH 09/12] Combine strings aid translators. --- includes/distributed-post-ui.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/includes/distributed-post-ui.php b/includes/distributed-post-ui.php index 2b4d9f7ee..b9e774e25 100644 --- a/includes/distributed-post-ui.php +++ b/includes/distributed-post-ui.php @@ -86,8 +86,20 @@ function distributed_to( $post ) {
- - %d connection', 'Distributed to %d connections', (int) $total_connections, 'distributor' ) ), (int) $total_connections ); ?> + ' . esc_html( $total_connections ) . '' + ) + ); + ?> (?)
From bd013975edabbe9a0561c3d53c7611d3684594a2 Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Thu, 1 Sep 2022 13:44:47 +1000 Subject: [PATCH 10/12] Avoid concatenation to aid translatability. --- includes/pull-ui.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/includes/pull-ui.php b/includes/pull-ui.php index 5d5aa0962..cb5c4048a 100644 --- a/includes/pull-ui.php +++ b/includes/pull-ui.php @@ -423,10 +423,15 @@ function dashboard() { if ( empty( $connection_list_table->connection_objects ) ) : $connection_now = 0; ?> - - - - + create one?', 'distributor' ), + esc_url( admin_url( 'post-new.php?post_type=dt_ext_connection' ) ) + ) + ); + ?>