Translation wordPresss using Java Script & jquery

Learn how to add simple, lightweight translation to your WordPress site using plain JavaScript and jQuery no heavy plugins required. In this tutorial, I’ll walk through the custom code I wrote, show you how it works, and explain how you can easily adapt it to translate your own theme content.

Delay to ensure the content is rendered if it's being generated by shortcode

				
					<script data-minify="1" src="https://mojibur.com/wp-content/cache/min/1/jquery-3.6.0.min.js?ver=1763573005" data-rocket-defer defer></script> <!-- Load jQuery if not already loaded -->
<script>window.addEventListener('DOMContentLoaded', function() {
  $(document).ready(function() {
    // Delay to ensure the content is rendered if it's being generated by shortcode
    setTimeout(function() {
      // Array of shortened weekday names
      var shortWeekdays = ['Lun', 'Mar', 'Mer', 'Jeu', 'Vendredi', 'Sam', 'Dim'];

      // Target each span element inside .flatpickr-weekdaycontainer and change its text
      $('.flatpickr-weekdaycontainer .flatpickr-weekday').each(function(index) {
        $(this).text(shortWeekdays[index]); // Replace text with the new shortened weekday names
      });

      // Array of month names to change
      var monthNames = {
        'October': 'Octobre',
        'November': 'Novembre',
        'December': 'Décembre'
      };

      // Change month names in the dropdown
      $('.flatpickr-monthDropdown-month').each(function() {
        var currentMonth = $(this).text(); // Get the current month name
        if (monthNames[currentMonth]) {
          $(this).text(monthNames[currentMonth]); // Replace with the corresponding French month name
        }
      });
    }, 1000); // Adjust the timeout value if needed
  });
});</script>
				
			

Attach click event to the button

				
					<script data-minify="1" src="https://mojibur.com/wp-content/cache/min/1/jquery-3.6.0.min.js?ver=1763573005" data-rocket-defer defer></script>

<script>window.addEventListener('DOMContentLoaded', function() {
    $(document).ready(function() {
        // Attach click event to the button
        $('.wpte-bf-btn').on('click', function() {
            // Use a timeout to ensure the popup content is ready
            setTimeout(function() {
                // Check if the elements exist before changing text
                if ($('.wte-process-nav-item#date-time a').length) {
                    $('.wte-process-nav-item#date-time a').text('Datum').append('<span class="arrow"></span>');
                }
                if ($('.wte-process-nav-item#package-type a').length) {
                    $('.wte-process-nav-item#package-type a').text('Ihre Reise').append('<span class="arrow"></span>');
                }
                if ($('.wte-process-nav-item#extra-services a').length) {
                    $('.wte-process-nav-item#extra-services a').text('Zusatzleistungen').append('<span class="arrow"></span>');
                }

                // Change the Booking Summary title
                if ($('.wte-booking-block-title').length) {
                    $('.wte-booking-block-title').text('Buchungsübersicht');
                }

                // Change the Starting Date text
                if ($('.wte-booking-starting-date strong').length) {
                    $('.wte-booking-starting-date strong').text('Startdatum:');
                }

                
            }, 300);
        });
 });
});</script>
				
			

One Response

Leave a Reply

Your email address will not be published. Required fields are marked *

Latest tutorials

Freelancer Mojibur
freelancer mojibur

Start a Project!

Interested in working together? Send a quick message or schedule a meeting. Ask questions, discuss details, and decide if we are a good fit.

Website Project Inquiry

This form helps me get a general idea. We’ll schedule a meeting soon to discuss everything in more detail!

Freelancer Mojibur

Contact person

For quick communication email at: freelancermojibur@gmail.com