WordPress.org

Ready to get started?Download WordPress

Forums

Polylang
[resolved] Polylang and Responsive Theme Calendar (3 posts)

  1. vasheck2
    Member
    Posted 10 months ago #

    Hi,

    First of all, thanks for the great plugin!

    I have an issue with an Event Calendar in my responsive theme (Churchope).

    More specifically, I have a bilingual site (En/Fr), English being the default one. When I load my Event Calendar the first time the calendar displays correctly in the appropriate language.

    If I go to the next month in the English version, the correct month (December 2013) / weekdays (Mon Tue Wed ...) are displayed on the calendar.

    If I switch the language to French calendar loads in the correct language (novembre 2013 - lun mar mer ...). Now my issue occurs when I click on the next month button ("d├ęcembre >"). The whole calendar switched back to English even though the rest of the page remain to be in French.

    When I change the default WP language the problem is identical but the languages are reversed. (French calendar OK, Eng loads OK but switches back to Fr)

    I believe this is the code that's not picking up the language settings.

    jQuery('#previous_month').live('click', function(){
    		sendCalendarData(jQuery(this), 'previous');
    		return false;
    	});
    jQuery('#next_month').live('click', function(){
    		sendCalendarData(jQuery(this), 'next');
    		return false;
    	});	
    
    function sendCalendarData(obj, month_to_show){
    
    	var form = obj.closest('form');
    	var form_data = {};
    
    	if(form && form.length)	{
    
    		var month = parseInt(jQuery('#calendar_month', form).val(), 10);
    		var year = parseInt(jQuery('#calendar_year', form).val(), 10);
    		var new_month = new_year = 0;
    
    		if(month_to_show == 'previous')	{
    			if(month == 1){
    				new_month = 12;
    				new_year = year - 1;
    			}
    			else{
    				new_month = month - 1;
    				new_year = year;
    			}
    		}
    		else{
    			if(month == 12){
    				new_month = 1;
    				new_year = year + 1;
    			}
    			else{
    				new_month = month + 1;
    				new_year = year;
    			}
    		}
    
    		form_data.calendar = true;
    		form_data.month = new_month;
    		form_data.year = new_year;
    		form_data.layout = jQuery('#calendar_layout', form).val();
    		form_data.category = jQuery('#calendar_category', form).val();
    		form_data.from = jQuery('#calendar_from', form).val();
    		form_data.to = jQuery('#calendar_to', form).val();
    
    		form_data.action = 'calendar_walker';
    
    		jQuery.ajax({
    
    		type: "POST",
    		url: ThemeData.admin_url,
    		data: form_data,
    		dataType: 'json',
    		success:function(response) {
    			if(response && typeof response == 'object' ){
    				form.parents('.events_calendar').html(response.html);
    				pushToHistory(response.html);
    			}
    		}
    	});
    	}
    }

    Any tips how to remedy the issue?

    Thank you!

    http://wordpress.org/plugins/polylang/

  2. Chouby
    Member
    Plugin Author

    Posted 10 months ago #

    Try adding:

    pll_load_front: 1

    to your ajax request.

    Otherwise you can try events-maker which is compatible with Polylang

  3. vasheck2
    Member
    Posted 10 months ago #

    Hi Chouby,

    Thanks very much for your help. Your suggested to add

    pll_load_front: 1 lead me to other related posts... and I eventually found a solution that worked for me. I save the code in as a php file, placed it in the plugin directory and activated it... The issue seems to be resolved for me. :)

    <?php
    /*
    Plugin name: GCE Load Polylang on Ajax requests
    */
    
    function gce_load_polylang_on_ajax() {
    	?>
    <script type="text/javascript">
    if (typeof jQuery != 'undefined') {
    	jQuery.ajaxSetup({
    		data: { pll_load_front: true }
    	});
    }
    </script>
    	<?php
    }
    
    add_action( 'wp_head', 'gce_load_polylang_on_ajax' );

    compliments of rosshanney
    https://gist.github.com/rosshanney/6202009

    thanks again for your help! it's much appreciated

Reply

You must log in to post.

About this Plugin

About this Topic