Making WordPress.org

Changeset 4764


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

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
5 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;
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-i18n.php

    r3511 r4764  
    1616     */
    1717    static function translate_term( $term ) {
     18        if ( 'en_US' == get_locale() ) {
     19            return $term;
     20        }
     21
    1822        if ( 'plugin_category' == $term->taxonomy ) {
    1923            $term->name = esc_html( translate_with_gettext_context( html_entity_decode( $term->name ), 'Plugin Category Name', 'wporg-plugins' ) );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r4620 r4764  
    454454        }
    455455
    456         if ( 'en_US' != get_locale() ) {
    457             add_filter( 'get_term', array( __NAMESPACE__ . '\I18n', 'translate_term' ) );
    458             add_filter( 'the_content', array( $this, 'translate_post_content' ), 1, 2 );
    459             add_filter( 'the_title', array( $this, 'translate_post_title' ), 1, 2 );
    460             add_filter( 'get_the_excerpt', array( $this, 'translate_post_excerpt' ), 1, 2 );
    461         }
     456        add_filter( 'get_term', array( __NAMESPACE__ . '\I18n', 'translate_term' ) );
     457        add_filter( 'the_content', array( $this, 'translate_post_content' ), 1, 2 );
     458        add_filter( 'the_title', array( $this, 'translate_post_title' ), 1, 2 );
     459        add_filter( 'get_the_excerpt', array( $this, 'translate_post_excerpt' ), 1, 2 );
    462460
    463461        // Instantiate our copy of the Jetpack_Search class.
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-i18n.php

    r4622 r4764  
    332332        }
    333333
    334         if ( ! $wp_locale ) {
     334        if ( ! $wp_locale || 'en_US' == $wp_locale ) {
    335335            return $content;
    336336        }
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-screenshots.php

    r4622 r4764  
    22namespace WordPressdotorg\Plugin_Directory\Shortcodes;
    33use WordPressdotorg\Plugin_Directory\Template;
     4use WordPressdotorg\Plugin_Directory\Plugin_i18n;
    45
    56/**
     
    3536
    3637            if ( $descriptions && ! empty( $descriptions[ (int)$image['resolution'] ] ) ) {
    37                 $screen_shot .= '<figcaption>' . $descriptions[ (int)$image['resolution'] ] . '</figcaption>';
     38                $caption = $descriptions[ (int)$image['resolution'] ];
     39                $caption = Plugin_I18n::instance()->translate( 'screenshot-' . $image['resolution'], $caption, [ 'post_id' => $$plugin->ID ] );
     40                $screen_shot .= '<figcaption>' . $caption . '</figcaption>';
    3841            }
    3942
Note: See TracChangeset for help on using the changeset viewer.