Making WordPress.org


Ignore:
Timestamp:
06/22/2016 04:06:56 PM (10 years ago)
Author:
ocean90
Message:

Plugin Directory: Display a locale banner on non-plugin details pages.

See #1728.

File:
1 edited

Legend:

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

    r3556 r3559  
    4242                $all_locales = wp_list_pluck( $locale_subdomain_assoc, 'locale' );
    4343
    44                 // Get the active language packs of the plugin.
    45                 $language_packs = $wpdb->get_results( $wpdb->prepare( "
    46                         SELECT *
    47                         FROM language_packs
    48                         WHERE
    49                                 type = 'plugin' AND
    50                                 domain = %s AND
    51                                 active = 1
    52                         GROUP BY language",
    53                         $plugin_slug
    54                 ) );
    55 
    56                 // Retrieve all the WordPress locales in which the plugin is translated.
    57                 $translated_locales = wp_list_pluck( $language_packs, 'language' );
     44                $is_plugin_request = ! empty( $plugin_slug );
     45
     46                if ( $is_plugin_request ) {
     47                        // Get the active language packs of the plugin.
     48                        $language_packs = $wpdb->get_results( $wpdb->prepare( "
     49                                SELECT *
     50                                FROM language_packs
     51                                WHERE
     52                                        type = 'plugin' AND
     53                                        domain = %s AND
     54                                        active = 1
     55                                GROUP BY language",
     56                                $plugin_slug
     57                        ) );
     58
     59                        // Retrieve all the WordPress locales in which the plugin is translated.
     60                        $translated_locales = wp_list_pluck( $language_packs, 'language' );
     61                } else {
     62                        $translated_locales = $all_locales;
     63                }
    5864
    5965                // Get the WordPress locales based on the HTTP accept language header.
    … …  
    7985                if ( 'en_US' === $current_locale ) {
    8086                        if ( 1 === count( $suggest_named_locales ) ) {
    81                                 $locale = key( $suggest_named_locales );
     87                                $locale   = key( $suggest_named_locales );
    8288                                $language = current( $suggest_named_locales );
    83                                 $suggest_string = sprintf(
    84                                         $this->translate( 'This plugin is also available in %s.', $locale ),
    85                                         sprintf(
    86                                                 '<a href="https://%s.wordpress.org/plugins-wp/%s/">%s</a>',
    87                                                 $locale_subdomain_assoc[ $locale ]->subdomain,
    88                                                 $plugin_slug,
    89                                                 $language
    90                                         )
    91                                 );
     89
     90                                if ( $is_plugin_request ) {
     91                                        $suggest_string = sprintf(
     92                                                $this->translate( 'This plugin is also available in %s.', $locale ),
     93                                                sprintf(
     94                                                        '<a href="https://%s.wordpress.org/plugins-wp/%s/">%s</a>',
     95                                                        $locale_subdomain_assoc[ $locale ]->subdomain,
     96                                                        $plugin_slug,
     97                                                        $language
     98                                                )
     99                                        );
     100                                } else {
     101                                        $suggest_string = sprintf(
     102                                                $this->translate( 'The plugin directory is also available in %s.', $locale ),
     103                                                sprintf(
     104                                                        '<a href="https://%s.wordpress.org/plugins-wp/">%s</a>',
     105                                                        $locale_subdomain_assoc[ $locale ]->subdomain,
     106                                                        $language
     107                                                )
     108                                        );
     109                                }
    92110                        } elseif ( ! empty( $suggest_named_locales ) ) {
    93111                                $primary_locale = key( $suggest_named_locales );
    … …  
    95113                                array_shift( $suggest_named_locales );
    96114
    97                                 $other_suggest = '';
    98                                 foreach ( $suggest_named_locales as $locale => $language ) {
    99                                         $other_suggest .= sprintf(
    100                                                 '<a href="https://%s.wordpress.org/plugins-wp/%s/">%s</a>, ',
    101                                                 $locale_subdomain_assoc[ $locale ]->subdomain,
    102                                                 $plugin_slug,
    103                                                 $language
     115                                if ( $is_plugin_request ) {
     116                                        $other_suggest = '';
     117                                        foreach ( $suggest_named_locales as $locale => $language ) {
     118                                                $other_suggest .= sprintf(
     119                                                        '<a href="https://%s.wordpress.org/plugins-wp/%s/">%s</a>, ',
     120                                                        $locale_subdomain_assoc[ $locale ]->subdomain,
     121                                                        $plugin_slug,
     122                                                        $language
     123                                                );
     124                                        }
     125
     126                                        $suggest_string = sprintf(
     127                                                $this->translate( 'This plugin is also available in %1$s (also: %2$s).', $primary_locale ),
     128                                                sprintf(
     129                                                        '<a href="https://%s.wordpress.org/plugins-wp/%s/">%s</a>',
     130                                                        $locale_subdomain_assoc[ $primary_locale ]->subdomain,
     131                                                        $plugin_slug,
     132                                                        $primary_language
     133                                                ),
     134                                                trim( $other_suggest, ' ,' )
    104135                                        );
    105                                 }
    106 
    107                                 $suggest_string = sprintf(
    108                                         $this->translate( 'This plugin is also available in %1$s (also: %2$s).', $primary_locale ),
    109                                         sprintf(
    110                                                 '<a href="https://%s.wordpress.org/plugins-wp/%s/">%s</a>',
    111                                                 $locale_subdomain_assoc[ $primary_locale ]->subdomain,
    112                                                 $plugin_slug,
    113                                                 $primary_language
    114                                         ),
    115                                         trim( $other_suggest, ' ,' )
    116                                 );
    117                         }
    118                 } elseif ( ! $current_locale_is_suggested && ! $current_locale_is_translated ) {
     136                                } else {
     137                                        $other_suggest = '';
     138                                        foreach ( $suggest_named_locales as $locale => $language ) {
     139                                                $other_suggest .= sprintf(
     140                                                        '<a href="https://%s.wordpress.org/plugins-wp/">%s</a>, ',
     141                                                        $locale_subdomain_assoc[ $locale ]->subdomain,
     142                                                        $language
     143                                                );
     144                                        }
     145
     146                                        $suggest_string = sprintf(
     147                                                $this->translate( 'The plugin directory is also available in %1$s (also: %2$s).', $primary_locale ),
     148                                                sprintf(
     149                                                        '<a href="https://%s.wordpress.org/plugins-wp/">%s</a>',
     150                                                        $locale_subdomain_assoc[ $primary_locale ]->subdomain,
     151                                                        $primary_language
     152                                                ),
     153                                                trim( $other_suggest, ' ,' )
     154                                        );
     155                                }
     156                        }
     157                } elseif ( ! $current_locale_is_suggested && ! $current_locale_is_translated && $is_plugin_request ) {
    119158                        $suggest_string = sprintf(
    120159                                $this->translate( 'This plugin is not available in %1$s yet. <a href="%2$s">Help translate it!</a>', $current_locale ),
    … …  
    248287                        2984794 => 'This plugin is also available in %1$s (also: %2$s).',
    249288                        2984795 => 'This plugin is not available in %1$s yet. <a href="%2$s">Help translate it!</a>',
     289                        0 => 'The plugin directory is also available in %s.',
     290                        0 => 'The plugin directory is also available in %1$s (also: %2$s).',
    250291                );
    251292
    252293                $original_id = array_search( $string, $strings, true );
     294                if ( ! $original_id ) {
     295                        return $string;
     296                }
    253297
    254298                require_once GLOTPRESS_LOCALES_PATH;
    … …  
    311355/* translators: 1: native language name, 2: URL to translate.wordpress.org */
    312356__( 'This plugin is not available in %1$s yet. <a href="%2$s">Help translate it!</a>', 'wporg-plugins' );
     357/* translators: %s: native language name. */
     358__( 'The plugin directory is also available in %s.', 'wporg-plugins' );
     359/* translators: 1: native language name, 2: other native language names, comma separated */
     360__( 'The plugin directory is also available in %1$s (also: %2$s).', 'wporg-plugins' );
Note: See TracChangeset for help on using the changeset viewer.