Making WordPress.org

Changeset 12535


Ignore:
Timestamp:
04/12/2023 08:05:53 PM (22 months ago)
Author:
ryelle
Message:

Plugin Directory: Locale Banner: Improve strings for suggesting multiple languages.

When more than one language is suggested, the string now reads as a list, to avoid implying a hierarchy in the suggestions.

This brings over the changes in [dotorg-20224] to the plugin locale banner.

Fixes #6600.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/api/routes/class-locale-banner.php

    r11297 r12535  
    119119
    120120            // Only one locale suggestion.
    121             if ( 1 === count( $suggest_named_locales ) ) {
    122                 $locale   = key( $suggest_named_locales );
    123                 $language = current( $suggest_named_locales );
     121            if ( ! empty( $suggest_named_locales ) ) {
     122                $primary_locale   = key( $suggest_named_locales );
     123                // Load translations for wp_sprintf_l().
     124                add_filter( 'wp_sprintf_l', function( $translations ) use( $primary_locale ) {
     125                    $translations['between']          = sprintf( $this->translate( '%1$s, %2$s', $primary_locale ), '', '' );
     126                    $translations['between_last_two'] = sprintf( $this->translate( '%1$s, and %2$s', $primary_locale ), '', '' );
     127                    $translations['between_only_two'] = sprintf( $this->translate( '%1$s and %2$s', $primary_locale ), '', '' );
     128
     129                    return $translations;
     130                } );
     131
     132                $suggestions = array();
     133                foreach ( $suggest_named_locales as $locale => $language ) {
     134                    $suggestions[] = sprintf(
     135                        '<a href="https://%s.wordpress.org%s">%s</a>',
     136                        $locale_subdomain_assoc[ $locale ]->subdomain,
     137                        esc_url( $current_path ),
     138                        $language
     139                    );
     140                }
    124141
    125142                if ( $is_plugin_request ) {
    126143                    $suggest_string = sprintf(
    127                         $this->translate( 'This plugin is also available in %1$s. <a href="%2$s">Help improve the translation!</a>', $locale ),
    128                         sprintf(
    129                             '<a href="https://%s.wordpress.org%s">%s</a>',
    130                             $locale_subdomain_assoc[ $locale ]->subdomain,
    131                             esc_url( $current_path ),
    132                             $language
    133                         ),
     144                        $this->translate( 'This plugin is also available in %1$s. <a href="%2$s">Help improve the translation!</a>', $primary_locale ),
     145                        wp_sprintf_l( '%l', $suggestions ),
    134146                        esc_url( 'https://translate.wordpress.org/projects/wp-plugins/' . $plugin_slug )
    135147                    );
    136148                } else {
    137149                    $suggest_string = sprintf(
    138                         $this->translate( 'The plugin directory is also available in %s.', $locale ),
    139                         sprintf(
    140                             '<a href="https://%s.wordpress.org%s">%s</a>',
    141                             $locale_subdomain_assoc[ $locale ]->subdomain,
    142                             esc_url( $current_path ),
    143                             $language
    144                         )
    145                     );
    146                 }
    147 
    148                 // Multiple locale suggestions.
    149             } elseif ( ! empty( $suggest_named_locales ) ) {
    150                 $primary_locale   = key( $suggest_named_locales );
    151                 $primary_language = current( $suggest_named_locales );
    152                 array_shift( $suggest_named_locales );
    153 
    154                 if ( $is_plugin_request ) {
    155                     $other_suggest = '';
    156                     foreach ( $suggest_named_locales as $locale => $language ) {
    157                         $other_suggest .= sprintf(
    158                             '<a href="https://%s.wordpress.org%s/">%s</a>, ',
    159                             $locale_subdomain_assoc[ $locale ]->subdomain,
    160                             esc_url( $current_path ),
    161                             $language
    162                         );
    163                     }
    164 
    165                     $suggest_string = sprintf(
    166                         $this->translate( 'This plugin is also available in %1$s (also: %2$s). <a href="%3$s">Help improve the translation!</a>', $primary_locale ),
    167                         sprintf(
    168                             '<a href="https://%s.wordpress.org%s">%s</a>',
    169                             $locale_subdomain_assoc[ $primary_locale ]->subdomain,
    170                             esc_url( $current_path ),
    171                             $primary_language
    172                         ),
    173                         trim( $other_suggest, ' ,' ),
    174                         esc_url( 'https://translate.wordpress.org/projects/wp-plugins/' . $plugin_slug )
    175                     );
    176                 } else {
    177                     $other_suggest = '';
    178                     foreach ( $suggest_named_locales as $locale => $language ) {
    179                         $other_suggest .= sprintf(
    180                             '<a href="https://%s.wordpress.org%s">%s</a>, ',
    181                             $locale_subdomain_assoc[ $locale ]->subdomain,
    182                             esc_url( $current_path ),
    183                             $language
    184                         );
    185                     }
    186 
    187                     $suggest_string = sprintf(
    188                         $this->translate( 'The plugin directory is also available in %1$s (also: %2$s).', $primary_locale ),
    189                         sprintf(
    190                             '<a href="https://%s.wordpress.org%s">%s</a>',
    191                             $locale_subdomain_assoc[ $primary_locale ]->subdomain,
    192                             esc_url( $current_path ),
    193                             $primary_language
    194                         ),
    195                         trim( $other_suggest, ' ,' )
     150                        $this->translate( 'The plugin directory is also available in %s.', $primary_locale ),
     151                        wp_sprintf_l( '%l', $suggestions ),
    196152                    );
    197153                }
     
    349305        $strings = array(
    350306            5118332 => 'This plugin is also available in %1$s. <a href="%2$s">Help improve the translation!</a>',
    351             5118333 => 'This plugin is also available in %1$s (also: %2$s). <a href="%3$s">Help improve the translation!</a>',
    352307            2984795 => 'This plugin is not translated into %1$s yet. <a href="%2$s">Help translate it!</a>',
    353308            3004513 => 'The plugin directory is also available in %s.',
    354             3004514 => 'The plugin directory is also available in %1$s (also: %2$s).',
     309
     310            // These are in wp/dev
     311            7233895 => '%1$s, %2$s',
     312            7234333 => '%1$s, and %2$s',
     313            7960    => '%1$s and %2$s',
    355314        );
    356315
     
    367326        }
    368327
    369         // Magic number: 348841 is meta/plugins-v3.
     328        // Magic number: 348841 is meta/plugins-v3, 2 is wp/dev.
    370329        $translations = $wpdb->get_results( $wpdb->prepare( "
    371330            SELECT
     
    375334                ON ts.id = t.translation_set_id
    376335            WHERE
    377                 project_id = 348841 AND slug = 'default' AND t.status = 'current'
     336                project_id IN ( 2, 348841 ) AND slug = 'default' AND t.status = 'current'
    378337            AND original_id = %d
    379338        ", $original_id ), OBJECT_K );
     
    391350
    392351// Strings for the POT file.
    393 /* translators: %s: native language name. */
     352/* translators: %s: native language name, possibly comma-separated list. */
    394353__( 'This plugin is also available in %1$s. <a href="%2$s">Help improve the translation!</a>', 'wporg-plugins' );
    395 /* translators: 1: native language name, 2: other native language names, comma separated */
    396 __( 'This plugin is also available in %1$s (also: %2$s). <a href="%3$s">Help improve the translation!</a>', 'wporg-plugins' );
    397354/* translators: 1: native language name, 2: URL to translate.wordpress.org */
    398355__( 'This plugin is not translated into %1$s yet. <a href="%2$s">Help translate it!</a>', 'wporg-plugins' );
    399 /* translators: %s: native language name. */
     356/* translators: %s: native language name, possibly comma-separated list. */
    400357__( 'The plugin directory is also available in %s.', 'wporg-plugins' );
    401 /* translators: 1: native language name, 2: other native language names, comma separated */
    402 __( 'The plugin directory is also available in %1$s (also: %2$s).', 'wporg-plugins' );
Note: See TracChangeset for help on using the changeset viewer.