[Resolved] Translating ‘read more’ on custom excerpts, multilingual site

Home Forums Support Translating ‘read more’ on custom excerpts, multilingual site

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1081788
    Dave

    I have a multilingual site using Polylang Pro. The site is up-to-date and runs the latest version of GP Premium (1.9.1?).

    We use custom excerpts for posts, and I seem to remember we needed to include the following code to get ‘Read More’ to appear:

    /* Filter - Remove default 'excerpt more'
    	---------------------------------------------------------------------------- */
    	function themeprefix_excerpt_more( $more ) {
    		return '';
    	}
    	add_filter('excerpt_more', 'themeprefix_excerpt_more', 21 );
    
    	/* Filter - Add 'read more' to custom excerpt
    	---------------------------------------------------------------------------- */
    	function themeprefix_get_the_excerpt( $excerpt ) {
    		$output = $excerpt;
    
    		$output = sprintf(
    			'%1$s <p class="read-more-container"><a class="button read-more" href="%2$s" title="">%3$s</a></p>',
    			$excerpt,
    			get_permalink(),
    			__( 'Read more', 'plugin' )
    		);
    
    		return $output;
    	}
    	add_filter( 'get_the_excerpt', 'themeprefix_get_the_excerpt' );

    We’re having trouble getting these strings to translate. I’ve checked that the ‘Read More’ text is blank in the customisr, and also tried adding this code, too.

    I’ll include the link for admins, the Spanish can be accessed by visiting /es/

    #1082200
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    What if you replace this:

    __( 'Read more', 'plugin' )

    With this?:

    __( 'Read more', 'gp-premium' )

    If not, you might need to use this function in Polylang: https://polylang.wordpress.com/documentation/documentation-for-developers/functions-reference/#pll__

    pll__( 'Read more' )

    Let me know if you need more info 🙂

    #1082374
    Dave

    Thanks, Tom!

    __( 'Read more', 'gp-premium' ) produces the same result. How would the Polylang function interact with the previous code?

    #1083453
    Tom
    Lead Developer
    Lead Developer

    Try this:

    add_action( 'init', function() {
        pll_register_string( 'gp-premium-read-more', 'Read more' );
    } );

    Then replace this:

    __( 'Read more', 'gp-premium' )

    With this:

    pll__( 'Read more' )

    Now it should show in your “String Translations” area in the Dashboard.

    #1083465
    Dave

    That’s perfect – thanks so much, Tom!

    #1085175
    Tom
    Lead Developer
    Lead Developer
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.