WordPress.org

Making WordPress.org

Changeset 3319


Ignore:
Timestamp:
06/08/16 02:55:55 (19 months ago)
Author:
tellyworth
Message:

Display translated readme content on the front-end.

This does on-the-fly translation rather than storing the data. It could and probably should eventually be changed to store that content in postmeta, in a way that is compatible with ElasticSearch indexing.

See #1691

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

Legend:

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

    r3293 r3319  
    217217        if ( 'en_US' != get_locale() ) { 
    218218            add_filter( 'get_term', array( __NAMESPACE__ . '\i18n', 'translate_term' ) ); 
     219            add_filter( 'the_content', array( $this, 'translate_post_content' ), 1, 2 ); 
     220            add_filter( 'the_title', array( $this, 'translate_post_title' ), 1, 2 ); 
     221            add_filter( 'get_the_excerpt', array( $this, 'translate_post_excerpt' ), 1 ); 
    219222        } 
    220223 
     
    439442        } 
    440443 
     444    } 
     445 
     446    /** 
     447     * Returns the requested page's content, translated. 
     448     * 
     449     * @param string $content 
     450     * @return string 
     451     */ 
     452    public function translate_post_content( $content, $section = null ) { 
     453        if ( is_null( $section ) ) { 
     454            return $content; 
     455        } 
     456        return Plugin_i18n::instance()->translate( $section, $content ); 
     457    } 
     458 
     459    /** 
     460     * Returns the requested page's content, translated. 
     461     * 
     462     * @param string $content 
     463     * @return string 
     464     */ 
     465    public function translate_post_title( $title, $post_id ) { 
     466        if ( $post_id === get_post()->ID ) { 
     467            return Plugin_i18n::instance()->translate( 'title', $title ); 
     468        } 
     469        return $title; 
     470    } 
     471 
     472    /** 
     473     * Returns the requested page's excerpt, translated. 
     474     * 
     475     * @param string $content 
     476     * @return string 
     477     */ 
     478    public function translate_post_excerpt( $excerpt ) { 
     479        return Plugin_i18n::instance()->translate( 'excerpt', $excerpt ); 
    441480    } 
    442481 
Note: See TracChangeset for help on using the changeset viewer.