• Resolved goozak

    (@goozak)


    I’m trying to figure out how we can translate the manual excerpt we added to our Posts. Since this string is not displayed in the Post, we can’t translate it. Your change log states, for version 2.6.7, “Added RSS Feed support for translating title, content and excerpt”, but I can’t find any mention of this in the doc…

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Alex

    (@alexcozmoslabs)

    Hi,

    The excerpt field is considered part of the RSS feed, so starting from version 2.6.7, TranslatePress added support to translate it for RSS purposes. This means that if you output the excerpt in your theme or RSS feed, it can now be translated.
    However, the excerpt is not automatically visible on the front-end unless your theme displays it. TranslatePress can only translate strings that are rendered in the HTML. So if the excerpt isn’t displayed anywhere on the page, it won’t appear in the visual translation editor.
    To translate it on the front-end, you would need to display the excerpt somewhere in your template.

      Thread Starter goozak

      (@goozak)

      With the help of Claude.AI, I’ve added this in my theme’s functions.php file to only display the excerpt when translating (since I don’t want to show it in the Post itself).

      function inject_excerpt_for_manual_translation() {
      global $post;

      // Only show in TranslatePress editor
      if ( !isset($_GET['trp-edit-translation']) || $_GET['trp-edit-translation'] !== 'preview' ) {
      return;
      }

      if ( !$post || !is_singular('post') ) {
      return;
      }

      $excerpt = get_the_excerpt($post->ID);

      if ( empty($excerpt) ) {
      return;
      }

      // ONLY visible in TranslatePress editor for translators
      echo '<div class="trp-excerpt-translation-area" style="border: 2px solid #0073aa; padding: 15px; margin: 20px 0; background: #f0f8ff;">';
      echo '<strong style="color: #0073aa;">Post Excerpt (Translate this for RSS feeds):</strong><br><br>';
      echo '<div class="trp-translatable-excerpt">' . $excerpt . '</div>';
      echo '</div>';
      }
      add_action('the_post', 'inject_excerpt_for_manual_translation');
      Plugin Support Alex

      (@alexcozmoslabs)

      Hi,

      This is a very smart custom approach. Thank you for sharing it with the community.

      Kind Regards,

      • This reply was modified 6 months, 1 week ago by Alex.
    Viewing 3 replies - 1 through 3 (of 3 total)

    The topic ‘Translating Manual Post Excerpt’ is closed to new replies.