Appointments+ gettext_with_context translation not working

I had a snippet in my theme's functions.php file which uses the gettext filter to translate some strings in the Appointments+ plugin. After updating the Appointments+ plugin, the function doesn't seem to be translating existing <span> tags properly, the tags are showing up in the front-end and the raw HTML (developer tools) show them as asci characters (< and >:wink:. Here's the full code snippet:

/* APPOINTMENTS CALENDAR - CHANGE ALL TEXT */
function wpmu_gettext_with_context( $translated_text, $untranslated_text, $domain ) {
if ( 'appointments' == $domain ) {
if (strpos($untranslated_text,'Our schedule from START to END') !== false) {
$translated_text = str_replace("Our schedule from START to END","<span>MAKE AN APPOINTMENT FOR</span><span>WEEK OF START</span>", $untranslated_text);
} else if (strpos($untranslated_text,'Click on a free time slot to apply for an appointment.') !== false) {
$translated_text = str_replace("Click on a free time slot to apply for an appointment.","Click light colored time slot to schedule.", $untranslated_text);
} else if (strpos($untranslated_text,'Please click here to confirm this appointment') !== false) {
$translated_text = str_replace("Please click here to confirm this appointment"," Confirm ", $untranslated_text);
} else if (strpos($untranslated_text,'Please check the appointment details below and confirm:') !== false) {
$translated_text = str_replace("Please check the appointment details below and confirm:","REVIEW APPOINTMENT & CONFIRM:", $untranslated_text);
} else if (strpos($untranslated_text,'<div class="appointments-confirmation-service"></div>') !== false) {
$translated_text = str_replace('<div class="appointments-confirmation-service"></div>','<div class="appointments-confirmation">Free Phone Consultation</div>', $untranslated_text);
/* adjust confirmation form labels */
} else if (strpos($untranslated_text,'Service provider:') !== false) {
$translated_text = str_replace("Service provider:","Consultation with:", $untranslated_text);
} else if (strpos($untranslated_text,'Your name:') !== false) {
$translated_text = str_replace("Your name:","Full Name:", $untranslated_text);
} else if (strpos($untranslated_text,'Your email:') !== false) {
$translated_text = str_replace("Your email:","Email:", $untranslated_text);
} else if (strpos($untranslated_text,'Your phone:') !== false) {
$translated_text = str_replace("Your phone:","Phone:", $untranslated_text);
} else if (strpos($untranslated_text,'We have received your appointment. Thanks!') !== false) {
$translated_text = str_replace("We have received your appointment. Thanks!",
"Your phone consultation has been scheduled! Now, check your email (or spam) to find -- K Dunn Conference Call Instructions.", $untranslated_text);
}
}

return $translated_text;
}
add_filter( 'gettext', 'wpmu_gettext_with_context', 10, 3 );

Please advice.

  • Paul
    • Site Builder, Child of Zeus

    Hi Patrick! I'm fine! How you doin'? I've already unlocked the WPMUDEV support access. I've moved the current version of Appointments+ plugin to the wp-contents folder, and am using a prior version of Appointments+ plugin that works. All other plugins and themes are up-to-date, so we know they have nothing to do with the anomaly. Hopefully, you have access to swap the appointments plugin folders to see what happens. Pay attention to the bold headline just above the appointment schedule. With the latest Appointments+ plugin, you'll notice the <span> open and close tags displaying...which is the issue....they have been converted to ascii characters in the source code. ...as if the PHP translation is not performing the correct "html_entity_decode" or something.

    https://brokersmap.com/appointment

  • Paul
    • Site Builder, Child of Zeus

    For ease of seeing the new bug, I've moved the new current version of Appointments+ back into the plugins folder. You can easily rename the current and prior version folders to see that the prior version does work... and I assume the engineers are working on this. When can I expect to receive a resolution to this new bug?

  • Paul
    • Site Builder, Child of Zeus

    I "could" write a sloppy javascript function to replace the ascii characters, like so...

    function wpmu_app_replace_text() {
        if ( is_page( 'appointment' )) {
        ?>
        <script type="text/javascript">
    	jQuery( document ).ready( function( $ ) {
    		var span1 = $('.appointments-wrapper').html();
    		span1 = span1.replace('<span>','');
    		$('.appointments-wrapper h3').html(span1);
    
    		var span2 = $('.appointments-wrapper').html();
    		span2 = span2.replace('</span><span>','<br />');
    		$('.appointments-wrapper').html(span2);
    
    		var span3 = $('.appointments-wrapper').html();
    		span3 = span3.replace('</span>','');
    		$('.appointments-wrapper').html(span3);
    	});
        </script>
        <?php
       } /* endif slug=appointment */
    }
    add_action('wp_footer', 'wpmu_app_replace_text');
    • Paul
      • Site Builder, Child of Zeus

      The above code that fixes the ascii character issues, should have the actual ascii "code" instead the ansii characters. ...but entering them as "code" in this thread, converted the ascii "code" back to regular characters, e.g. <span>, instead of & lt ; span & gt ;.

  • Patrick Freitas
    • Staff

    Hi Paul

    Sorry for a delay here.

    I tested the translation function on my end and had the same result, however as said previous on chat this is not a WPMU function. This is actually a general WP function - https://codex.wordpress.org/Plugin_API/Filter_Reference/gettext_with_context.

    I tried to use the html_entity_decode() function but I got no fixed the problem.
    I'll keep looking for any solution for this, also I'll be forwarding this thread to our SLS and they can have a fresh closer look to get a solution for this function.

    Best Regards,
    Patrick Freitas

    • Paul
      • Site Builder, Child of Zeus

      Thanks, Patrick! To clarify... You understand that with everything WP updated, but an earlier version of Appointments+, the gettext_with_context function works...Place the current version of Appointments+ in there and it doesn't work. How is that possible it's a WP issue? Can't we backtrack what's allowing the function to work in the old version of Appointments+, and reinstate that in the new version?

  • Panos
    • SLS

    Hey Paul ,

    There has been a change and currently uses esc_html__() that's why you see that markup code.

    For now there is no way other than modifying files directly or with js as you have suggested. In the meanwhile I have asked main Dev if it is possible to add some filters to override those values.

    We'll keep you updated once we have any news :slight_smile:

    Kind regards!

    • Paul
      • Site Builder, Child of Zeus

      Thanks, Panos! To clarify, your dev team changed a function in Appointments+ that causes this new behavior..."esc_html__()". And the changes cannot be reversed because this new version of "esc_html__()" is being used for new functions in the new version of Appointments+? ...That's why the old version of Appointments+ works with a fully updated WP and plugins being used?

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.