admin管理员组

文章数量:1314049

I am creating translation for a custom theme and specifically custom template file of the theme and user Poedit to create the pot template.

After translating the file one line in the template won't translate no matter what I do.

<?php echo __( 'Featured', 'mytextdomain' ); ?>

Possibly helpful additional info:

  1. this line isn't located within wordpress loop.
  2. If I remove echo part and leave only __() it wont even output word "Featured" in English
  3. I substitute echo__() with _e() "Featured" outputs.

Similar issue also custom "read more" form functions.php isn't translated.

function new_excerpt_more($more) { global $post; return ' &hellip;' . __('<a class="more-link" href="'. get_permalink($post->ID) . '">Read More</a>'); }

There's got to be something I'm doing wrong here since everything else translates and outputs except these two instances.

any ideas what am I doing wrong?

I am creating translation for a custom theme and specifically custom template file of the theme and user Poedit to create the pot template.

After translating the file one line in the template won't translate no matter what I do.

<?php echo __( 'Featured', 'mytextdomain' ); ?>

Possibly helpful additional info:

  1. this line isn't located within wordpress loop.
  2. If I remove echo part and leave only __() it wont even output word "Featured" in English
  3. I substitute echo__() with _e() "Featured" outputs.

Similar issue also custom "read more" form functions.php isn't translated.

function new_excerpt_more($more) { global $post; return ' &hellip;' . __('<a class="more-link" href="'. get_permalink($post->ID) . '">Read More</a>'); }

There's got to be something I'm doing wrong here since everything else translates and outputs except these two instances.

any ideas what am I doing wrong?

Share Improve this question asked Nov 27, 2020 at 0:34 annksweannkswe 231 silver badge6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Your first line of code looks ok, are you sure you have a translation for the 'Featured' string in your PO file? Your second issue is an excellent example of how you should not use the gettext functions. You are trying to translate dynamic string '<a class="more-link" href="'. get_permalink($post->ID) . '">Read More</a>' for which you should have the corresponding translation for every different get_permalink($post->ID) value. What you should do instead is

return ' &hellip;<a class="more-link" href="'. get_permalink( $post->ID ) . '">' . __( 'Read More', 'mytextdomain' ) . '</a>';

or

return sprintf( ' &hellip;<a class="more-link" href="%s">%s</a>', get_permalink( $post->ID ), __( 'Read More', 'mytextdomain' ) );

and translate only the 'Read More' phrase.

本文标签: Translation is not being output in one instance