From 94c2212de883bc3c03da1f73f696d2207210b077 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Wed, 13 Jul 2016 17:31:15 +0000 Subject: [PATCH] Update/Install: Give context to some install/update strings to allow for differentiation between theme and plugin translations. Props swissspidy, SergeyBiryukov. Fixes #37290. git-svn-id: https://develop.svn.wordpress.org/trunk@38057 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/ajax-actions.php | 2 ++ src/wp-admin/includes/theme.php | 6 +++++- src/wp-admin/includes/update.php | 26 ++++++++++++++++++-------- src/wp-admin/js/updates.js | 16 ++++++++++++---- src/wp-admin/theme-install.php | 22 +++++++++++++++------- src/wp-admin/themes.php | 18 +++++++++++++++--- src/wp-includes/script-loader.php | 25 ++++++++++++++++++------- tests/qunit/fixtures/updates.js | 15 ++++++++++----- 8 files changed, 95 insertions(+), 35 deletions(-) diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index 5e04365f2f..9751bc5bef 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -3344,6 +3344,8 @@ function wp_ajax_install_theme() { wp_send_json_error( $status ); } + $status['themeName'] = wp_get_theme( $slug )->get( 'Name' ); + if ( current_user_can( 'switch_themes' ) ) { if ( is_multisite() ) { $status['activateUrl'] = add_query_arg( array( diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php index d758480f39..6f25348280 100644 --- a/src/wp-admin/includes/theme.php +++ b/src/wp-admin/includes/theme.php @@ -635,7 +635,11 @@ function customize_themes_print_templates() { <# if ( ! data.active ) { #>
- + +
<# } #> diff --git a/src/wp-admin/includes/update.php b/src/wp-admin/includes/update.php index 88452190d0..eff6f7647c 100644 --- a/src/wp-admin/includes/update.php +++ b/src/wp-admin/includes/update.php @@ -690,7 +690,7 @@ function wp_print_admin_notice_templates() { * @type string colspan The number of table columns this row spans. * @type string content The row content. * } - * + * * The delete template takes one argument with four values: * * param {object} data { @@ -716,13 +716,23 @@ function wp_print_update_row_templates() { diff --git a/src/wp-admin/js/updates.js b/src/wp-admin/js/updates.js index 0de60b5a1c..24a8186a24 100644 --- a/src/wp-admin/js/updates.js +++ b/src/wp-admin/js/updates.js @@ -508,7 +508,9 @@ $message.text( wp.updates.l10n.installing ); } - $message.addClass( 'updating-message' ); + $message + .addClass( 'updating-message' ) + .attr( 'aria-label', wp.updates.l10n.pluginInstallingLabel.replace( '%s', $message.data( 'name' ) ) ); wp.a11y.speak( wp.updates.l10n.installingMsg, 'polite' ); @@ -535,6 +537,7 @@ $message .removeClass( 'updating-message' ) .addClass( 'updated-message installed button-disabled' ) + .attr( 'aria-label', wp.updates.l10n.pluginInstalledLabel.replace( '%s', response.pluginName ) ) .text( wp.updates.l10n.installed ); wp.a11y.speak( wp.updates.l10n.installedMsg, 'polite' ); @@ -547,6 +550,7 @@ // Transform the 'Install' button into an 'Activate' button. $message.removeClass( 'install-now installed button-disabled updated-message' ).addClass( 'activate-now button-primary' ) .attr( 'href', response.activateUrl ) + .attr( 'aria-label', wp.updates.l10n.activatePluginLabel.replace( '%s', response.pluginName ) ) .text( wp.updates.l10n.activatePlugin ); }, 1000 ); } @@ -595,7 +599,7 @@ $button .removeClass( 'updating-message' ).addClass( 'button-disabled' ) - .attr( 'aria-label', wp.updates.l10n.installFailedLabel.replace( '%s', response.pluginName ) ) + .attr( 'aria-label', wp.updates.l10n.pluginInstallFailedLabel.replace( '%s', $button.data( 'name' ) ) ) .text( wp.updates.l10n.installFailedShort ); wp.a11y.speak( errorMessage, 'assertive' ); @@ -1003,7 +1007,9 @@ $message.data( 'originaltext', $message.html() ); } - $message.text( wp.updates.l10n.installing ); + $message + .text( wp.updates.l10n.installing ) + .attr( 'aria-label', wp.updates.l10n.themeInstallingLabel.replace( '%s', $message.data( 'name' ) ) ); wp.a11y.speak( wp.updates.l10n.installingMsg, 'polite' ); // Remove previous error messages, if any. @@ -1032,6 +1038,7 @@ $message = $card.find( '.button-primary' ) .removeClass( 'updating-message' ) .addClass( 'updated-message disabled' ) + .attr( 'aria-label', wp.updates.l10n.themeInstalledLabel.replace( '%s', response.themeName ) ) .text( wp.updates.l10n.installed ); wp.a11y.speak( wp.updates.l10n.installedMsg, 'polite' ); @@ -1045,6 +1052,7 @@ .attr( 'href', response.activateUrl ) .removeClass( 'theme-install updated-message disabled' ) .addClass( 'activate' ) + .attr( 'aria-label', wp.updates.l10n.activateThemeLabel.replace( '%s', response.themeName ) ) .text( wp.updates.l10n.activateTheme ); } @@ -1098,7 +1106,7 @@ $button .removeClass( 'updating-message' ) - .attr( 'aria-label', wp.updates.l10n.installFailedLabel.replace( '%s', $card.find( '.theme-name' ).text() ) ) + .attr( 'aria-label', wp.updates.l10n.themeInstallFailedLabel.replace( '%s', $button.data( 'name' ) ) ) .text( wp.updates.l10n.installFailedShort ); wp.a11y.speak( errorMessage, 'assertive' ); diff --git a/src/wp-admin/theme-install.php b/src/wp-admin/theme-install.php index 646203e4c0..050a7b97b5 100644 --- a/src/wp-admin/theme-install.php +++ b/src/wp-admin/theme-install.php @@ -248,17 +248,25 @@ if ( $tab ) {
<# if ( data.installed ) { #> + <# if ( data.activate_url ) { #> - + <# } #> <# if ( data.customize_url ) { #> - + <# } else { #> - + <# } #> <# } else { #> - - + + + <# } #>
@@ -274,9 +282,9 @@ if ( $tab ) { <# if ( data.installed ) { #> - + <# } else { #> - + <# } #>
diff --git a/src/wp-admin/themes.php b/src/wp-admin/themes.php index 580318e80c..59ba3dd017 100644 --- a/src/wp-admin/themes.php +++ b/src/wp-admin/themes.php @@ -277,7 +277,11 @@ foreach ( $themes as $theme ) : - + + @@ -402,7 +406,11 @@ $can_install = current_user_can( 'install_themes' ); <# } #> <# } else { #> - + + <# } #>
@@ -456,8 +464,12 @@ $can_install = current_user_can( 'install_themes' );
+ <# if ( data.actions.activate ) { #> - + <# } #>
diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 2945b480fb..c2dadf21df 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -628,12 +628,18 @@ function wp_default_scripts( &$scripts ) { 'installFailedShort' => __( 'Install Failed!' ), /* translators: Error string for a failed installation */ 'installFailed' => __( 'Installation failed: %s' ), - /* translators: Plugin/Theme name and version */ - 'installingLabel' => __( 'Installing %s...' ), // no ellipsis - /* translators: Plugin/Theme name and version */ - 'installedLabel' => __( '%s installed!' ), - /* translators: Plugin/Theme name and version */ - 'installFailedLabel' => __( '%s installation failed' ), + /* translators: Plugin name and version */ + 'pluginInstallingLabel' => _x( 'Installing %s...', 'plugin' ), // no ellipsis + /* translators: Theme name and version */ + 'themeInstallingLabel' => _x( 'Installing %s...', 'theme' ), // no ellipsis + /* translators: Plugin name and version */ + 'pluginInstalledLabel' => _x( '%s installed!', 'plugin' ), + /* translators: Theme name and version */ + 'themeInstalledLabel' => _x( '%s installed!', 'theme' ), + /* translators: Plugin name and version */ + 'pluginInstallFailedLabel' => _x( '%s installation failed', 'plugin' ), + /* translators: Theme name and version */ + 'themeInstallFailedLabel' => _x( '%s installation failed', 'theme' ), 'installingMsg' => __( 'Installing... please wait.' ), 'installedMsg' => __( 'Installation completed successfully.' ), /* translators: Activation URL */ @@ -649,10 +655,15 @@ function wp_default_scripts( &$scripts ) { 'deleteFailed' => __( 'Deletion failed: %s' ), 'deleted' => __( 'Deleted!' ), 'livePreview' => __( 'Live Preview' ), + /* translators: %s: Theme name */ 'activatePlugin' => is_network_admin() ? __( 'Network Activate' ) : __( 'Activate' ), 'activateTheme' => is_network_admin() ? __( 'Network Enable' ) : __( 'Activate' ), + /* translators: %s: Plugin name */ + 'activatePluginLabel' => is_network_admin() ? _x( 'Network Activate %s', 'plugin' ) : _x( 'Activate %s', 'plugin' ), + /* translators: %s: Theme name */ + 'activateThemeLabel' => is_network_admin() ? _x( 'Network Activate %s', 'theme' ) : _x( 'Activate %s', 'theme' ), 'activateImporter' => __( 'Activate importer' ), - 'unknownError' => __( 'An unknown error occured' ), + 'unknownError' => __( 'An unknown error occurred' ), 'pluginsFound' => __( 'Number of plugins found: %d' ), 'noPluginsFound' => __( 'No plugins found. Try a different search.' ), ), diff --git a/tests/qunit/fixtures/updates.js b/tests/qunit/fixtures/updates.js index d570aa67f5..8332039713 100644 --- a/tests/qunit/fixtures/updates.js +++ b/tests/qunit/fixtures/updates.js @@ -22,9 +22,12 @@ window._wpUpdatesSettings = { 'installed': 'Installed!', 'installFailedShort': 'Install Failed!', 'installFailed': 'Installation failed: %s', - 'installingLabel': 'Installing %s...', // No ellipsis - 'installedLabel': '%s installed!', - 'installFailedLabel': '%s installation failed', + 'pluginInstallingLabel': 'Installing %s...', // No ellipsis + 'themeInstallingLabel': 'Installing %s...', // No ellipsis + 'pluginInstalledLabel': '%s installed!', + 'themeInstalledLabel': '%s installed!', + 'pluginInstallFailedLabel': '%s installation failed', + 'themeInstallFailedLabel': '%s installation failed', 'installingMsg': 'Installing... please wait.', 'installedMsg': 'Installation completed successfully.', 'importerInstalledMsg': 'Importer installed successfully. Activate plugin & run importer', @@ -37,9 +40,11 @@ window._wpUpdatesSettings = { 'deleted': 'Deleted!', 'livePreview': 'Live Preview', 'activatePlugin': 'Activate', - 'activateTheme': 'Activate', + 'activateTheme': 'Activate', + 'activatePluginLabel': 'Activate %s', + 'activateThemeLabel': 'Activate %s', 'activateImporter': 'Activate importer', - 'unknownError': 'An unknown error occured', + 'unknownError': 'An unknown error occurred', 'pluginsFound': 'Number of plugins found: %d', 'noPluginsFound': 'No plugins found. Try a different search.' }