Skip to content

Commit

Permalink
Merge pull request #3079 from 10up/fix/issue-3059
Browse files Browse the repository at this point in the history
Properly internationalize strings in JS
  • Loading branch information
felipeelia authored Oct 26, 2022
2 parents a160a5a + c45b40a commit 84a77d3
Show file tree
Hide file tree
Showing 21 changed files with 214 additions and 78 deletions.
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ The `develop` branch is the development branch which means it contains the next
1. Props: Update `CREDITS.md` file with any new contributors, confirm maintainers are accurate.
1. Readme updates: Make any other readme changes as necessary. `README.md` is geared toward GitHub and `readme.txt` contains WordPress.org-specific content. The two are slightly different.
1. New files: Check to be sure any new files/paths that are unnecessary in the production version are included in `.distignore`.
1. POT file: Run `wp i18n make-pot . lang/elasticpress.pot` and commit the file.
1. Release date: Double check the release date in both changelog files.
1. Merge: Merge the release branch/PR into `develop`, then make a non-fast-forward merge from `develop` into `trunk` (`git checkout trunk && git merge --no-ff develop`). `trunk` contains the stable development version.
1. Test: While still on the `trunk` branch, test for functionality locally.
1. Push: Push your `trunk` branch to GitHub (e.g. `git push origin trunk`).
Expand All @@ -56,6 +58,8 @@ Pre-releases are different from normal versions because (1) they are not publish
1. Props: Update `CREDITS.md` file with any new contributors, confirm maintainers are accurate.
1. Readme updates: Make any other readme changes as necessary. `README.md` is geared toward GitHub and `readme.txt` contains WordPress.org-specific content. The two are slightly different.
1. New files: Check to be sure any new files/paths that are unnecessary in the production version are included in `.distignore`.
1. POT file: Run `wp i18n make-pot . lang/elasticpress.pot` and commit the file.
1. Release date: Double check the release date in both changelog files.
1. Merge: Merge the release branch/PR into the next version branch (`4.x.x`, for example).
1. Test: Checkout the next version branch locally and build assets like the GitHub Action will do (see `.github/workflows/push-deploy.yml`)
1. Release: Create a [new pre-release](https://github.com/10up/elasticpress/releases/new), naming the tag and the release with the new version number, and targeting the next version branch branch. Paste the release changelog from `CHANGELOG.md` into the body of the release and include a link to the closed issues on the [milestone](https://github.com/10up/elasticpress/milestone/#?closed=1). **ATTENTION**: Make sure to check the `This is a pre-release` checkbox, so the release is not published on WordPress.org.
Expand All @@ -74,6 +78,8 @@ There may be cases where we have an urgent/important fix that ideally gets into
1. Props: Update `CREDITS.md` file with any new contributors, confirm maintainers are accurate.
1. Readme updates: Make any other readme changes as necessary. `README.md` is geared toward GitHub and `readme.txt` contains WordPress.org-specific content. The two are slightly different.
1. New files: Check to be sure any new files/paths that are unnecessary in the production version are included in `.distignore`.
1. POT file: Run `wp i18n make-pot . lang/elasticpress.pot` and commit the file.
1. Release date: Double check the release date in both changelog files.
1. Merge: Merge the release branch/PR into `trunk`. `trunk` contains the stable development version.
1. Test: While still on the `trunk` branch, test for functionality locally.
1. Push: Push your `trunk` branch to GitHub (e.g. `git push origin trunk`).
Expand Down
4 changes: 2 additions & 2 deletions assets/js/blocks/facets/meta/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"supports": {
"html": false
},
"editorScript": "file:/../../../../../dist/js/facets-meta-block-script.min.js",
"style": "file:/../../../../../dist/css/facets-styles.min.css"
"editorScript": "ep-facets-meta-block-script",
"style": "file:/../../../../../dist/css/facets-styles.css"
}
4 changes: 2 additions & 2 deletions assets/js/blocks/facets/taxonomy/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"supports": {
"html": false
},
"editorScript": "file:/../../../../../dist/js/facets-block-script.min.js",
"style": "file:/../../../../../dist/css/facets-styles.min.css"
"editorScript": "ep-facets-block-script",
"style": "file:/../../../../../dist/css/facets-styles.css"
}
4 changes: 2 additions & 2 deletions assets/js/blocks/related-posts/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
"align": true
},
"usesContext": ["postId"],
"editorScript": "file:/../../../../dist/js/related-posts-block-script.min.js",
"style": "file:/../../../../dist/css/related-posts-block-styles.min.css"
"editorScript": "ep-related-posts-block-script",
"style": "file:/../../../../dist/css/related-posts-block-styles.css"
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const ActiveContraint = ({ label, onClick }) => {
return createPortal(
<SmallButton
aria-label={sprintf(
/* translators: %s: Constraint label. */
/* translators: %s: Filter term name. */
__('Remove filter: %s', 'elasticpress'),
label,
)}
Expand Down
63 changes: 53 additions & 10 deletions includes/classes/AdminNotices.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,18 @@ protected function process_auto_activate_sync_notice() {
$feature = Features::factory()->get_registered_feature( $auto_activate_sync );

if ( defined( 'EP_DASHBOARD_SYNC' ) && ! EP_DASHBOARD_SYNC ) {
$html = sprintf( esc_html__( 'Dashboard sync is disabled. The ElasticPress %s feature has been auto-activated! You will need to reindex using WP-CLI for it to work.', 'elasticpress' ), esc_html( is_object( $feature ) ? $feature->title : '' ) );
$html = sprintf(
/* translators: Feature name */
esc_html__( 'Dashboard sync is disabled. The ElasticPress %s feature has been auto-activated! You will need to reindex using WP-CLI for it to work.', 'elasticpress' ),
esc_html( is_object( $feature ) ? $feature->title : '' )
);
} else {
$html = sprintf( __( 'The ElasticPress %1$s feature has been auto-activated! You will need to <a href="%2$s">run a sync</a> for it to work.', 'elasticpress' ), esc_html( is_object( $feature ) ? $feature->title : '' ), esc_url( $url ) );
$html = sprintf(
/* translators: 1. Feature name; 2: Sync page URL */
__( 'The ElasticPress %1$s feature has been auto-activated! You will need to <a href="%2$s">run a sync</a> for it to work.', 'elasticpress' ),
esc_html( is_object( $feature ) ? $feature->title : '' ),
esc_url( $url )
);
}

return [
Expand Down Expand Up @@ -255,7 +264,11 @@ protected function process_upgrade_sync_notice() {
if ( defined( 'EP_DASHBOARD_SYNC' ) && ! EP_DASHBOARD_SYNC ) {
$html = esc_html__( 'Dashboard sync is disabled. The new version of ElasticPress requires that you delete all data and start a fresh sync using WP-CLI.', 'elasticpress' );
} else {
$html = sprintf( __( 'The new version of ElasticPress requires that you <a href="%s">delete all data and start a fresh sync</a>.', 'elasticpress' ), esc_url( $url ) );
$html = sprintf(
/* translators: Sync Page URL */
__( 'The new version of ElasticPress requires that you <a href="%s">delete all data and start a fresh sync</a>.', 'elasticpress' ),
esc_url( $url )
);
}

$notice = esc_html__( 'Please note that some ElasticPress functionality may be impaired and/or content may not be searchable until the full sync has been performed.', 'elasticpress' );
Expand Down Expand Up @@ -315,7 +328,11 @@ protected function process_no_sync_notice() {
if ( defined( 'EP_DASHBOARD_SYNC' ) && ! EP_DASHBOARD_SYNC ) {
$html = esc_html__( 'Dashboard sync is disabled, but ElasticPress is almost ready to go. Trigger a sync from WP-CLI.', 'elasticpress' );
} else {
$html = sprintf( __( 'ElasticPress is almost ready to go. You just need to <a href="%s">sync your content</a>.', 'elasticpress' ), esc_url( $url ) );
$html = sprintf(
/* translators: Sync Page URL */
__( 'ElasticPress is almost ready to go. You just need to <a href="%s">sync your content</a>.', 'elasticpress' ),
esc_url( $url )
);
}

return [
Expand Down Expand Up @@ -361,9 +378,13 @@ protected function process_need_setup_notice() {
}

return [
'html' => sprintf( __( 'ElasticPress is almost ready to go. You just need to <a href="%s">enter your settings</a>.', 'elasticpress' ), esc_url( $url ) ),
'type' => 'info',
'dismiss' => 'dashboard' !== $screen,
'html' => sprintf(
/* translators: Sync Page URL */
__( 'ElasticPress is almost ready to go. You just need to <a href="%s">enter your settings</a>.', 'elasticpress' ),
esc_url( $url )
),
];
}

Expand Down Expand Up @@ -414,9 +435,14 @@ protected function process_es_below_compat_notice() {

if ( 1 === version_compare( EP_ES_VERSION_MIN, $major_es_version ) ) {
return [
'html' => sprintf( __( 'Your Elasticsearch version %1$s is below the minimum required Elasticsearch version %2$s. ElasticPress may or may not work properly.', 'elasticpress' ), esc_html( $es_version ), esc_html( EP_ES_VERSION_MIN ) ),
'type' => 'error',
'dismiss' => true,
'html' => sprintf(
/* translators: 1. Current Elasticsearch version; 2. Minimum required ES version */
__( 'Your Elasticsearch version %1$s is below the minimum required Elasticsearch version %2$s. ElasticPress may or may not work properly.', 'elasticpress' ),
esc_html( $es_version ),
esc_html( EP_ES_VERSION_MIN )
),
];
}

Expand Down Expand Up @@ -461,9 +487,14 @@ protected function process_es_above_compat_notice() {

if ( -1 === version_compare( EP_ES_VERSION_MAX, $major_es_version ) ) {
return [
'html' => sprintf( __( 'Your Elasticsearch version %1$s is above the maximum required Elasticsearch version %2$s. ElasticPress may or may not work properly.', 'elasticpress' ), esc_html( $es_version ), esc_html( EP_ES_VERSION_MAX ) ),
'type' => 'warning',
'dismiss' => true,
'html' => sprintf(
/* translators: 1. Current Elasticsearch version; 2. Maximum supported ES version */
__( 'Your Elasticsearch version %1$s is above the maximum required Elasticsearch version %2$s. ElasticPress may or may not work properly.', 'elasticpress' ),
esc_html( $es_version ),
esc_html( EP_ES_VERSION_MAX )
),
];
}
}
Expand Down Expand Up @@ -503,7 +534,7 @@ protected function process_different_server_type_notice() {

$doc_url = 'https://10up.github.io/ElasticPress/tutorial-compatibility.html';
$html = sprintf(
/* translator: Document page URL */
/* translators: Document page URL */
__( 'Your server software is not supported. To learn more about server compatibility please <a href="%s">visit our documentation</a>.', 'elasticpress' ),
esc_url( $doc_url )
);
Expand Down Expand Up @@ -563,14 +594,21 @@ protected function process_host_error_notice() {
$response_error = get_transient( 'ep_es_info_response_error' );
}

$html = sprintf( __( 'There is a problem with connecting to your Elasticsearch host. ElasticPress can <a href="%1$s">try your host again</a>, or you may need to <a href="%2$s">change your settings</a>.', 'elasticpress' ), esc_url( add_query_arg( 'ep-retry', 1 ) ), esc_url( $url ) );
$html = sprintf(
/* translators: 1. Current URL with retry parameter; 2. Settings Page URL */
__( 'There is a problem with connecting to your Elasticsearch host. ElasticPress can <a href="%1$s">try your host again</a>, or you may need to <a href="%2$s">change your settings</a>.', 'elasticpress' ),
esc_url( add_query_arg( 'ep-retry', 1 ) ),
esc_url( $url )
);

if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
if ( ! empty( $response_code ) ) {
/* translators: Response Code Number */
$html .= '<span class="notice-error-es-response-code"> ' . sprintf( __( 'Response Code: %s', 'elasticpress' ), esc_html( $response_code ) ) . '</span>';
}

if ( ! empty( $response_error ) ) {
/* translators: Response Code Message */
$html .= '<span class="notice-error-es-response-error"> ' . sprintf( __( 'Response error: %s', 'elasticpress' ), esc_html( $response_error ) ) . '</span>';
}
}
Expand Down Expand Up @@ -639,6 +677,7 @@ protected function process_maybe_wrong_mapping_notice() {
);

if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
/* translators: 1. Current mapping file; 2. Mapping file that should be used */
$html .= '<span class="notice-error-es-response-code"> ' . sprintf( esc_html__( 'Current mapping: %1$s. Expected mapping: %2$s', 'elasticpress' ), esc_html( $mapping_file_current ), esc_html( $mapping_file_wanted ) ) . '</span>';
}

Expand Down Expand Up @@ -693,9 +732,13 @@ protected function process_yellow_health_notice() {
}

return [
'html' => sprintf( __( 'It looks like one or more of your indices are running on a single node. While this won\'t prevent you from using ElasticPress, depending on your site\'s specific needs this can represent a performance issue. Please check the <a href="%1$s">Index Health</a> page where you can check the health of all of your indices.', 'elasticpress' ), $url ),
'type' => 'warning',
'dismiss' => true,
'html' => sprintf(
/* translators: Index Health URL */
__( 'It looks like one or more of your indices are running on a single node. While this won\'t prevent you from using ElasticPress, depending on your site\'s specific needs this can represent a performance issue. Please check the <a href="%s">Index Health</a> page where you can check the health of all of your indices.', 'elasticpress' ),
$url
),
];
}
}
Expand Down
10 changes: 9 additions & 1 deletion includes/classes/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ public function activate_feature( $args, $assoc_args ) {
$status = $feature->requirements_status();

if ( 2 === $status->code ) {
/* translators: Error message */
WP_CLI::error( sprintf( esc_html__( 'Feature requirements are not met: %s', 'elasticpress' ), implode( "\n\n", (array) $status->message ) ) );
} elseif ( 1 === $status->code ) {
/* translators: Warning message */
WP_CLI::warning( sprintf( esc_html__( 'Feature is usable but there are warnings: %s', 'elasticpress' ), implode( "\n\n", (array) $status->message ) ) );
}

Expand Down Expand Up @@ -265,6 +267,7 @@ private function put_mapping_helper( $args, $assoc_args ) {
continue;
}

/* translators: 1. Indexable; 2. Site ID */
WP_CLI::line( sprintf( esc_html__( 'Adding %1$s mapping for site %2$d…', 'elasticpress' ), esc_html( strtolower( $indexable->labels['singular'] ) ), (int) $site['blog_id'] ) );

$indexable->delete_index();
Expand Down Expand Up @@ -300,6 +303,7 @@ private function put_mapping_helper( $args, $assoc_args ) {
continue;
}

/* translators: Indexable label */
WP_CLI::line( sprintf( esc_html__( 'Adding %s mapping…', 'elasticpress' ), esc_html( strtolower( $indexable->labels['singular'] ) ) ) );

$indexable->delete_index();
Expand Down Expand Up @@ -336,6 +340,7 @@ private function put_mapping_helper( $args, $assoc_args ) {
continue;
}

/* translators: Indexable label */
WP_CLI::line( sprintf( esc_html__( 'Adding %s mapping…', 'elasticpress' ), esc_html( strtolower( $indexable->labels['singular'] ) ) ) );

$indexable->delete_index();
Expand Down Expand Up @@ -510,7 +515,7 @@ public function delete_index( $args, $assoc_args ) {
switch_to_blog( $site['blog_id'] );

foreach ( $non_global_indexable_objects as $indexable ) {

/* translators: 1. Indexable label; 2. Site ID */
WP_CLI::line( sprintf( esc_html__( 'Deleting %1$s index for site %2$d…', 'elasticpress' ), esc_html( strtolower( $indexable->labels['singular'] ) ), (int) $site['blog_id'] ) );

$result = $indexable->delete_index();
Expand All @@ -526,6 +531,7 @@ public function delete_index( $args, $assoc_args ) {
}
} else {
foreach ( $non_global_indexable_objects as $indexable ) {
/* translators: Index Label (plural) */
WP_CLI::line( sprintf( esc_html__( 'Deleting index for %s…', 'elasticpress' ), esc_html( strtolower( $indexable->labels['plural'] ) ) ) );

$result = $indexable->delete_index();
Expand All @@ -539,6 +545,7 @@ public function delete_index( $args, $assoc_args ) {
}

foreach ( $global_indexable_objects as $indexable ) {
/* translators: Index Label (plural) */
WP_CLI::line( sprintf( esc_html__( 'Deleting index for %s…', 'elasticpress' ), esc_html( strtolower( $indexable->labels['plural'] ) ) ) );

$result = $indexable->delete_index();
Expand Down Expand Up @@ -572,6 +579,7 @@ public function recreate_network_alias( $args, $assoc_args ) {
$indexables = Indexables::factory()->get_all( false );

foreach ( $indexables as $indexable ) {
/* translators: Index Label */
WP_CLI::line( sprintf( esc_html__( 'Recreating %s network alias…', 'elasticpress' ), esc_html( strtolower( $indexable->labels['singular'] ) ) ) );

$indexable->delete_network_alias();
Expand Down
7 changes: 5 additions & 2 deletions includes/classes/Feature/Autosuggest/Autosuggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,17 @@ public function enqueue_scripts() {

wp_enqueue_script(
'elasticpress-autosuggest',
EP_URL . 'dist/js/autosuggest-script.min.js',
EP_URL . 'dist/js/autosuggest-script.js',
Utils\get_asset_info( 'autosuggest-script', 'dependencies' ),
Utils\get_asset_info( 'autosuggest-script', 'version' ),
true
);

wp_set_script_translations( 'elasticpress-autosuggest', 'elasticpress' );

wp_enqueue_style(
'elasticpress-autosuggest',
EP_URL . 'dist/css/autosuggest-styles.min.css',
EP_URL . 'dist/css/autosuggest-styles.css',
Utils\get_asset_info( 'autosuggest-styles', 'dependencies' ),
Utils\get_asset_info( 'autosuggest-styles', 'version' )
);
Expand Down Expand Up @@ -896,6 +898,7 @@ public function epio_allowed_parameters() {
wp_sprintf( esc_html__( 'Post Types: %l', 'elasticpress' ), $allowed_params['postTypes'] ),
wp_sprintf( esc_html__( 'Post Status: %l', 'elasticpress' ), $allowed_params['postStatus'] ),
wp_sprintf( esc_html__( 'Search Fields: %l', 'elasticpress' ), $allowed_params['searchFields'] ),
/* translators: List of files allowed to be returned wrapped by var_export() */
wp_sprintf( esc_html__( 'Returned Fields: %s', 'elasticpress' ), var_export( $allowed_params['returnFields'], true ) ), // phpcs:ignore
];

Expand Down
6 changes: 4 additions & 2 deletions includes/classes/Feature/Comments/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,17 @@ public function widget( $args, $instance ) {
// Enqueue Script & Styles
wp_enqueue_script(
'elasticpress-comments',
EP_URL . 'dist/js/comments-script.min.js',
EP_URL . 'dist/js/comments-script.js',
Utils\get_asset_info( 'comments-script', 'dependencies' ),
Utils\get_asset_info( 'comments-script', 'version' ),
true
);

wp_set_script_translations( 'elasticpress-comments', 'elasticpress' );

wp_enqueue_style(
'elasticpress-comments',
EP_URL . 'dist/css/comments-styles.min.css',
EP_URL . 'dist/css/comments-styles.css',
Utils\get_asset_info( 'comments-styles', 'dependencies' ),
Utils\get_asset_info( 'comments-styles', 'version' )
);
Expand Down
8 changes: 5 additions & 3 deletions includes/classes/Feature/Facets/Facets.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function admin_scripts( $hook ) {

wp_enqueue_style(
'elasticpress-facets-admin',
EP_URL . 'dist/css/facets-admin-styles.min.css',
EP_URL . 'dist/css/facets-admin-styles.css',
Utils\get_asset_info( 'facets-admin-styles', 'dependencies' ),
Utils\get_asset_info( 'facets-admin-styles', 'version' )
);
Expand All @@ -210,15 +210,17 @@ public function admin_scripts( $hook ) {
public function front_scripts() {
wp_register_script(
'elasticpress-facets',
EP_URL . 'dist/js/facets-script.min.js',
EP_URL . 'dist/js/facets-script.js',
Utils\get_asset_info( 'facets-script', 'dependencies' ),
Utils\get_asset_info( 'facets-script', 'version' ),
true
);

wp_set_script_translations( 'elasticpress-facets', 'elasticpress' );

wp_register_style(
'elasticpress-facets',
EP_URL . 'dist/css/facets-styles.min.css',
EP_URL . 'dist/css/facets-styles.css',
Utils\get_asset_info( 'facets-styles', 'dependencies' ),
Utils\get_asset_info( 'facets-styles', 'version' )
);
Expand Down
Loading

0 comments on commit 84a77d3

Please sign in to comment.