Making WordPress.org


Ignore:
Timestamp:
01/24/2017 10:59:27 AM (8 years ago)
Author:
dd32
Message:

Plugin Directory: Use translated data for the api.wordpress.org info endpoint.

  • Also translates screenshot titles on the front end
  • Also uses plugin tags in API info endpoint rather than defunct categories.

See #2112
Fixes #2415

File:
1 edited

Legend:

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

    r4717 r4764  
    22namespace WordPressdotorg\Plugin_Directory\API\Routes;
    33use WordPressdotorg\Plugin_Directory\Plugin_Directory;
     4use WordPressdotorg\Plugin_Directory\Plugin_i18n;
    45use WordPressdotorg\Plugin_Directory\Template;
    56use WordPressdotorg\Plugin_Directory\Tools;
     
    5556        }
    5657
     58        // Support returning API data in different locales, even on wordpress.org (for api.wordpress.org usage)
     59        if ( ! empty( $request['locale'] ) && !in_array( strtolower( $request['locale'] ), array( 'en_us', 'en' ) ) ) {
     60            switch_to_locale( $request['locale'] );
     61        }
     62
    5763        $post_id = $post->ID;
    5864
    5965        $result = array();
    60         $result['name'] = $post->post_title;
     66        $result['name'] = get_the_title();
    6167        $result['slug'] = $post->post_name;
    6268        $result['version'] = get_post_meta( $post_id, 'version', true ) ?: '0.0';
     
    116122        if ( !empty( $result['sections']['faq'] ) ) {
    117123            $result['sections']['faq'] = $this->get_simplified_faq_markup( $result['sections']['faq'] );
    118         } 
     124        }
    119125       
    120126        $result['description'] = $result['sections']['description'];
    121127
    122         $result['short_description'] = $post->post_excerpt;
     128        $result['short_description'] = get_the_excerpt();
    123129        $result['download_link'] = Template::download_link( $post );
    124130
     
    132138         */
    133139        foreach ( $screen_shots as $image ) {
    134             $result['screenshots'][ $image['resolution'] ] = array(
    135                 'src'     => Template::get_asset_url( $post, $image ),
    136                 'caption' => array_key_exists( $image['resolution'], $descriptions ) ? $descriptions[ $image['resolution'] ] : ''
    137             );
     140            $src = Template::get_asset_url( $post, $image );
     141            $caption = '';
     142            if ( $descriptions && !empty( $description[ (int)$image['resolution'] ] ) ) {
     143                $caption = $description[ (int)$image['resolution'] ];
     144                $caption = Plugin_I18n::instance()->translate( 'screenshot-' . $image['resolution'], $caption, [ 'post_id' => $$post->ID ] );
     145            }
     146
     147            $result['screenshots'][ $image['resolution'] ] = compact( 'src', 'caption' );
    138148        }
    139149
     
    145155
    146156        $result['tags'] = array();
    147         if ( $terms = get_the_terms( $post->ID, 'plugin_category' ) ) {
     157        if ( $terms = get_the_terms( $post->ID, 'plugin_tags' ) ) {
    148158            foreach ( $terms as $term ) {
    149159                $result['tags'][ $term->slug ] = $term->name;
Note: See TracChangeset for help on using the changeset viewer.