Making WordPress.org

Changeset 5218


Ignore:
Timestamp:
03/30/2017 09:44:49 PM (8 years ago)
Author:
obenland
Message:

Plugin Directory: Update developers section.

Replaces lists with full sentences and adds locale details.

See #1824.
Fixes #2629.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-i18n.php

    r4764 r5218  
    431431     */
    432432    public function find_all_translations_for_plugin( $slug, $branch, $min_percent = 0 ) {
     433        $post = Plugin_Directory::get_plugin_post( $slug );
     434
     435        return wp_filter_object_list( $this->get_locales( $post, $branch, $min_percent ), null, null, 'wp_locale' );
     436    }
     437
     438    /**
     439     * Returns a list of locale objects for a given plugin slug and branch.
     440     *
     441     * @param int|\WP_Post|null $post        Optional. Post ID or post object. Defaults to global $post.
     442     * @param string            $branch      Optional. Branch - 'stable-readme' for example. Default: 'stable'.
     443     * @param int               $min_percent Optional. Only return locales where percent_translated is >= this value.
     444     *                                       Default: 95.
     445     * @return array
     446     */
     447    public function get_locales( $post = null, $branch = 'stable', $min_percent = 95 ) {
     448        $post = get_post( $post );
    433449
    434450        // This naively hits the API. It could probably be re-written to query the DB instead.
    435         $api_url = esc_url_raw( 'https://translate.wordpress.org/api/projects/wp-plugins/' . $slug . '/' . $branch, array( 'https' ) );
    436 
    437         $out    = array();
    438         $http   = new \WP_Http();
    439         $result = $http->request( $api_url );
     451        $api_url = esc_url_raw( 'https://translate.wordpress.org/api/projects/wp-plugins/' . $post->post_name . '/' . $branch, array( 'https' ) );
     452
     453        $locales = array();
     454        $http    = new \WP_Http();
     455        $result  = $http->request( $api_url );
    440456
    441457        if ( ! is_wp_error( $result ) ) {
    442458            $data = json_decode( $result['body'] );
    443459
    444             if ( $data && isset( $data->translation_sets ) ) {
    445                 foreach ( $data->translation_sets as $translation ) {
    446                     if ( $translation->percent_translated >= $min_percent ) {
    447                         $out[] = $translation->wp_locale;
    448                     }
    449                 }
     460            if ( ! empty( $data->translation_sets ) ) {
     461                $locales = array_filter( $data->translation_sets, function( $locale ) use ( $min_percent ) {
     462                    return $locale->percent_translated >= $min_percent;
     463                } );
    450464            }
    451465        }
    452466
    453         return $out;
     467        return $locales;
    454468    }
    455469}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-developers.php

    r5214 r5218  
    11<?php
    22namespace WordPressdotorg\Plugin_Directory\Shortcodes;
    3 use WordPressdotorg\Plugin_Directory\Template;
     3use WordPressdotorg\Plugin_Directory\Plugin_I18n;
    44use WordPressdotorg\Plugin_Directory\Tools;
    55
     
    1616    static function display() {
    1717        $post   = get_post();
    18         $output = '<p>' . sprintf( __( '%s is open source software. The following people have contributed to this plugin.', 'wporg-plugins' ), get_the_title( $post ) ) . '</p>';
     18        $slug   = $post->post_name;
     19        $title  = get_the_title( $post );
     20        $output = '<p>' . sprintf( __( '%s is open source software. The following people have contributed to this plugin.', 'wporg-plugins' ), $title ) . '</p>';
    1921
    2022        ob_start();
     
    2830        $output .= ob_get_clean();
    2931
     32        $locales = Plugin_I18n::instance()->get_locales();
     33        $output .= '<p>';
     34
     35        if ( ! empty( $locales ) ) {
     36            $locales_list = implode( ', ', array_map( function( $locale ) use ( $slug ) {
     37                return sprintf( '<a href="%1$s">%2$s</a>', esc_url( "{$locale->locale}.wordpress.org/plugins/{$slug}/" ), $locale->name );
     38            }, $locales ) );
     39            /* Translators: 1: Plugin name; 2: Number of locales; 3: List of locales; */
     40            $output .= sprintf( '%1$s has been translated into these %2$d locales: %3$s.', $title, count( $locales ), $locales_list ) . ' ';
     41            $output .= sprintf(
     42                /* Translators: URL to translator view; */
     43                __( 'Thank you to <a href="%s">the translators</a> for their contributions.', 'wporg-plugins' ),
     44                esc_url( "https://translate.wordpress.org/projects/wp-plugins/{$slug}/contributors" )
     45            );
     46            $output .= '<br />';
     47        }
     48
     49        /* Translators: 1: GlotPress URL; 2: Plugin name; */
     50        $output .= sprintf( __( '<a href="%1$s">Translate %2$s into your language.</a>', 'wporg-plugins' ), esc_url( 'https://translate.wordpress.org/projects/wp-plugins/' . $slug ), $title );
     51        $output .= '</p>';
     52
     53        $output   .= '<h3>' . __( 'Interested in development?', 'wporg-plugins' ) . '</h3>';
     54        /* Translators: 1: Trac URL; 2: Development log URL; 3: RSS URL; */
     55        $format    = __( '<a href="%1$s">Browse the code</a> or subscribe to the <a href="%2$s">development log</a> by <a href="%3$s">RSS</a>.' );
     56        $email_url = '';
     57
    3058        if ( is_user_logged_in() ) {
     59            /* Translators: 1: Trac URL; 2: Development log URL; 3: RSS URL; 4: Email subscription URL; */
     60            $format     = __( '<a href="%1$s">Browse the code</a> or subscribe to the <a href="%2$s">development log</a> by <a href="%4$s">email</a> or <a href="%3$s">RSS</a>.' );
    3161            $subscribed = Tools::subscribed_to_plugin_commits( $post, get_current_user_id() );
    32 
    33             $subscribe_change_url = esc_url( add_query_arg( array(
     62            $email_url  = esc_url( add_query_arg( array(
    3463                '_wpnonce' => wp_create_nonce( 'wp_rest' ),
    3564                ( $subscribed ? 'unsubscribe' : 'subscribe' ) => '1',
    36             ), home_url( 'wp-json/plugins/v1/plugin/' . $post->post_name . '/commit-subscription' ) ) );
     65            ), home_url( "wp-json/plugins/v1/plugin/{$slug}/commit-subscription" ) ) );
    3766        }
    3867
    39         return $output .
    40             '<h3>' . __( 'Browse the code', 'wporg-plugins' ) . '</h3>' .
    41             '<ul>' .
    42                 '<li>' .
    43                     '<a href="' . esc_url( "https://plugins.trac.wordpress.org/log/{$post->post_name}/" ) . '" rel="nofollow">' . __( 'Development Log', 'wporg-plugins' ) . '</a>' . "\n" .
    44                     '<a href="' . esc_url( "https://plugins.trac.wordpress.org/log/{$post->post_name}/?limit=100&mode=stop_on_copy&format=rss" ) . '" rel="nofollow"><img src="https://s.w.org/style/images/feedicon.png" /></a>' .
    45                 '</li>' .
    46                 '<li><a href="' . esc_url( "https://plugins.svn.wordpress.org/{$post->post_name}/" ) . '" rel="nofollow">' . __( 'Subversion Repository', 'wporg-plugins' ) . '</a></li>' .
    47                 '<li><a href="' . esc_url( "https://plugins.trac.wordpress.org/browser/{$post->post_name}/" ) . '" rel="nofollow">' . __( 'Browse in Trac', 'wporg-plugins' ) . '</a></li>' .
    48                 '<li><a href="' . esc_url( "https://translate.wordpress.org/projects/wp-plugins/{$post->post_name}/" ) . '" rel="nofollow">' . __( 'Translation Contributors', 'wporg-plugins' ) . '</a></li>' .
    49                  ( !is_user_logged_in() ? '' : (
    50                     $subscribed ?
    51                     "<li><a href='$subscribe_change_url'>" . __( 'Unsubscribe from plugin commits', 'wporg-plugins' ) . '</a></li>' :
    52                     "<li><a href='$subscribe_change_url'>" . __( 'Subscribe to plugin commits via email', 'wporg-plugins' ) . '</a></li>'
    53                  ) ) .
    54             '</ul>';
     68        $output .= '<p>' . sprintf(
     69            $format,
     70            esc_url( "https://plugins.trac.wordpress.org/browser/{$slug}/" ),
     71            esc_url( "https://plugins.trac.wordpress.org/log/{$slug}/" ),
     72            esc_url( "https://plugins.trac.wordpress.org/log/{$slug}/?limit=100&mode=stop_on_copy&format=rss" ),
     73            $email_url
     74        ) . '</p>';
     75
     76        return $output;
    5577    }
    5678}
Note: See TracChangeset for help on using the changeset viewer.