• Resolved Marc Lacroix

    (@marcusig)


    Hi there!

    I’m using the filter add_filter( 'trp_stop_translating_page', '__return_true' ); to stop translating an Ajax request which returns a PDF file.

    I have something like this:

    add_action('wp_ajax_nopriv__save_to_pdf',  'ajax_save_to_pdf' );
    function ajax_save_to_pdf() {
    add_filter( 'trp_stop_translating_page', '__return_true' );
    // ... the logic
    echo $dompdf->output();
    exit;
    }

    This successfully disable the translation (which was breaking the PDF).

    However the strings contain Translatepress markup.

    E.g. #!trpst#trp-gettext data-trpgettextoriginal=9736#!trpen#Total#!trpst#/trp-gettext#!trpen#

    How can I prevent this? Do I need to add the filter earlier in the WP cycle?

    Marc

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Anghel Emanuel

    (@anghelemanuel99)

    Hello there,

    Thank you for reaching out to us!

    You can try with the “Disable translation for gettext strings” feature from Settings->TranslatePress->Advanced tab and see if this could solve the problem.

    Let me know about this!

    Kind Regards,

    Thread Starter Marc Lacroix

    (@marcusig)

    Hi there,

    Thanks. I don’t want to have to change settings, as this is to add compatibility with a plugin.
    See related topic here.

    This is what I’ve done:

    add_action( 'plugins_loaded', function() {
    if ( isset( $_REQUEST['action'] ) && 'mkl_save_to_pdf' === $_REQUEST['action'] ) {
    add_filter( 'trp_stop_translating_page', '__return_true' );
    add_action( 'trp_before_running_hooks', function( $trp_loader ) {
    $trp = TRP_Translate_Press::get_trp_instance();
    $gettext_manager = $trp->get_component( 'gettext_manager' );
    $trp_loader->remove_hook( 'init', 'create_gettext_translated_global', $gettext_manager );
    $trp_loader->remove_hook( 'shutdown', 'machine_translate_gettext', $gettext_manager );
    // $trp_loader->add_action( 'mkl_pdf_before_buffer_output', $gettext_manager, 'machine_translate_gettext', 100 );
    }, 10, 1);
    }
    }, -10 );

    I wonder if there is a way to keep the automatic translation for the PDF content?

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Issue when using trp_stop_translating_page filter’ is closed to new replies.