Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix translatability of strings. #935

Merged
merged 12 commits into from
Sep 4, 2022
30 changes: 21 additions & 9 deletions assets/js/gutenberg-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,9 +62,14 @@ 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 || 'Content'
dtGutenberg.postTypeSingular ||
_x(
'content',
'generic term for post content',
'distributor'
)
) }
</button>
</div>
Expand Down Expand Up @@ -109,10 +114,14 @@ const RenderDistributedTo = () => {
return (
<span id="distributed-to">
{ sprintf(
/** translators: 1: Number of connections content distributed to. */
__( 'Distributed to %1$s connection%2$s.', 'distributor' ),
dtGutenberg.syndicationCount,
'1' === dtGutenberg.syndicationCount ? '' : 's'
/* translators: 1: Number of connections content distributed to. */
_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
) }
</span>
);
Expand All @@ -124,8 +133,11 @@ const RenderDistributedTo = () => {
const RenderDistributedFrom = () => {
return (
<span id="distributed-from">
{ __( 'Distributed on: ', 'distributor' ) }
<strong> { dtGutenberg.syndicationTime } </strong>
{ sprintf(
/* translators: 1: Syndication date and time. */
__( 'Distributed on: %1$s', 'distributor' ),
dtGutenberg.syndicationTime
) }
</span>
);
};
Expand Down
17 changes: 9 additions & 8 deletions assets/js/gutenberg-syndicated-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
),
Expand All @@ -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,
} );

Expand All @@ -40,17 +41,17 @@ 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. 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,
dtGutenberg.postTypeSingular
);

actions.push( {
label: __( 'restore it.', 'distributor' ),
label: __( 'Relink to original.', 'distributor' ),
url: dtGutenberg.linkNonceUrl,
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,27 @@ public static function credentials_form( $args = array() ) {
) {
?>
<div class="card">
<p><?php esc_html_e( 'To connect, first ', 'distributor' ); ?>
<a href="https://developer.wordpress.com/apps/"><?php esc_html_e( 'create an application with the WordPress.com applications manager', 'distributor' ); ?></a>.</p>
<p><?php esc_html_e( 'Use the following redirect URL when creating your application: ', 'distributor' ); ?><br />
<strong><?php echo esc_url( admin_url( 'post.php' ) ); ?></strong></p>
<p>
<?php
echo wp_kses_post(
sprintf(
/* translators: %1$s URL of wordpress.com applications manager. */
__( 'To connect, first <a href="%1$s">create an application with the WordPress.com applications manager</a>.', 'distributor' ),
esc_url( 'https://developer.wordpress.com/apps/' )
)
);
?>
</p>

<p>
<?php
printf(
/* translators: %1$s Redirect URL for WordPress.com application displayed as bold text. */
esc_html__( 'Use the following redirect URL when creating your application: %1$s', 'distributor' ),
'<strong>' . esc_url( admin_url( 'post.php' ) ) . '</strong>'
);
?>
</p>
<?php

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
}
}

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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' ) );
}

/**
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -629,15 +629,15 @@ 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 );

$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();
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down
8 changes: 4 additions & 4 deletions includes/classes/PullListTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -639,7 +639,7 @@ public function extra_tablenav( $which ) {
?>

<label class="dt-as-draft" for="dt-as-draft-<?php echo esc_attr( $which ); ?>">
<input type="checkbox" id="dt-as-draft-<?php echo esc_attr( $which ); ?>" name="dt_as_draft" value="draft" <?php checked( $as_draft ); ?>> <?php esc_html_e( 'Pull in as draft', 'distributor' ); ?>
<input type="checkbox" id="dt-as-draft-<?php echo esc_attr( $which ); ?>" name="dt_as_draft" value="draft" <?php checked( $as_draft ); ?>> <?php esc_html_e( 'Pull as draft', 'distributor' ); ?>
</label>
<?php endif; ?>
</div>
Expand Down
16 changes: 14 additions & 2 deletions includes/distributed-post-ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,20 @@ function distributed_to( $post ) {

<div class="misc-pub-section curtime misc-pub-curtime">
<span id="distributed-to">
<?php /* translators: %d: number of connections */ ?>
<?php printf( wp_kses_post( _n( 'Distributed to <strong>%d</strong> connection', 'Distributed to <strong>%d</strong> connections', (int) $total_connections, 'distributor' ) ), (int) $total_connections ); ?>
<?php
echo wp_kses_post(
sprintf(
/* translators: %d: number of connections */
_n(
'Distributed to %1$s connection.',
'Distributed to %1$s connections.',
(int) $total_connections, // Syndication count is a string, so we need to convert it to a number.
'distributor'
),
'<strong>' . esc_html( $total_connections ) . '</strong>'
)
);
?>
<a class="open-distributor-help">(?)</a>
</span>
</div>
Expand Down
13 changes: 9 additions & 4 deletions includes/pull-ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,15 @@ function dashboard() {
if ( empty( $connection_list_table->connection_objects ) ) :
$connection_now = 0;
?>
<?php esc_html_e( 'No Connections to Pull from,', 'distributor' ); ?>

<a href="<?php echo esc_url( admin_url( 'post-new.php?post_type=dt_ext_connection' ) ); ?>"><?php esc_html_e( 'Create One?', 'distributor' ); ?></a>

<?php
echo wp_kses_post(
sprintf(
/* translators: %s: link to add new connection */
__( 'No connections to pull from, <a href="%s">create one?</a>', 'distributor' ),
esc_url( admin_url( 'post-new.php?post_type=dt_ext_connection' ) )
)
);
?>
<?php else : ?>
<?php esc_html_e( 'Pull Content from', 'distributor' ); ?>
<select id="pull_connections" name="connection" method="get">
Expand Down
22 changes: 18 additions & 4 deletions includes/push-ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -584,11 +584,25 @@ function menu_content() {
<div class="inner">
<p class="syndicated-notice">
<?php /* translators: %s: post type name */ ?>
<?php printf( esc_html__( 'This %s has been distributed from', 'distributor' ), esc_html( strtolower( $post_type_object->labels->singular_name ) ) ); ?>
<a href="<?php echo esc_url( $site_url ); ?>"><?php echo esc_html( $blog_name ); ?></a>.

<?php esc_html_e( 'You can ', 'distributor' ); ?>
<a href="<?php echo esc_url( $post_url ); ?>"><?php esc_html_e( 'view the original', 'distributor' ); ?></a>
<?php
echo wp_kses_post(
sprintf(
/* translators: 1) Distributor post type singular name, 2) Source of content. */
__( 'This %1$s was distributed from %2$s.', 'distributor' ),
esc_html( strtolower( $post_type_object->labels->singular_name ) ),
'<a href="' . esc_url( $site_url ) . '">' . esc_html( $blog_name ) . '</a>'
)
);

if ( ! empty( $post_url ) ) {
?>
<a href="<?php echo esc_url( $post_url ); ?>" target="_blank">
<?php esc_html_e( 'View original', 'distributor' ); ?>
</a>
<?php
}
?>
</p>
</div>
</div>
Expand Down
Loading