Skip to main content
The cart is empty

How to translate Divi Events Calendar

This tutorial give you some code to change in the Divi Event Calendar Module to make it working with Falang and Falang for Divi

You can start to read the first part of the documentation here : Translate The event Calendar with Falang

  1. add language code (local) to the ajax call when the calendar is displayed
  2. translate title and link in the calendar view
  3. add filter in function.php
  4. translate Event 

1) Add language to ajax call

the javascript file calendar_shjow.js need to be changed wp-content/plugins/divi-event-calendar-module/includes/packages/calender_show.js

line 485

url: myAjax.ajaxurl + "?action=fetch_Events&locale="+language+"&dateformat=" + myAjax.date_format +

the language (locale) parameter is added , this locale is the local from the document en-US and not a wordpress locale en_US or the slug 

Be carrefull the local javascript need to be use and not the cdn javascript

in case the modified file is not loaded you can change in wp-content/plugins/divi-event-calendar-module/includes/modules/DiviEventCalendar/DiviEventCalendar.php line 3624

if($this->props['show_cdn_link']=="on"){
  wp_register_script("calendar_show", plugins_url().'/divi-event-calendar-module/includes/packages/calender_show.js',"","9.0");//sbou put a number to force reload

2) Translate title and link in calendar view

in the file wp-content/plugins/divi-event-calendar-module/divi-event-calendar-module.php line 574

replace

$e["tooltip_title"]=$show_title=="on"?'<div class="event_title_style '.$disable_event_title_link.'"><h3 class="title_text"> <a calss="'.$disable_event_title_link.'" href="' . $e['custom_event_link_url'].'" target="'.$custom_event_link_target.'">'.$event->post_title.'</a></h3></div>':"";
$e["title"]='<a class="'.$disable_event_calendar_title_link.'" href="'.$e['custom_event_link_url'].'" target="'.$custom_event_link_target.'">'.$event->post_title .'</a>';//sbou

by

$e["tooltip_title"]=$show_title=="on"?'<div class="event_title_style '.$disable_event_title_link.'"><h3 class="title_text"> <a calss="'.$disable_event_title_link.'" href="' . $e['custom_event_link_url'].'" target="'.$custom_event_link_target.'">'.apply_filters('tribe_get_event_cm_title',$event->post_title,$event->ID).'</a></h3></div>':"";
$e["title"]='<a class="'.$disable_event_calendar_title_link.'" href="'.$e['custom_event_link_url'].'" target="'.$custom_event_link_target.'">'.apply_filters('tribe_get_event_cm_title',$event->post_title,$event).'</a>';//sbou

3) add filter in function.php

You need to add this 2 filters in the function.php of your theme  , in this exemple the link is supposed to be "event"

/*
 * Translate the link in the event calendar
 * from divi-event-calendar-module/divi-event-calendar-module.php
 * the-events-calendar/src/functions/template-tags/link.php
 * */
function falang_tribe_get_event_link( $link, $post_id, $full_link, $url ) {
  if (isset($_REQUEST['locale'])){
    //locale on page don't have the right format
    $locale = str_replace("-","_",$_REQUEST['locale']);
    $language = Falang()->get_model()->get_language_by_locale($locale);
    $has_lang_in_link = strpos($link,'/'.$language->slug.'/');
    if (isset($language) && !$has_lang_in_link){
      $post = get_post($post_id);
      $link = str_replace('event',$language->slug.'/event',$link);
    }
  }
  return $link;
}

add_filter('tribe_get_event_link','falang_tribe_get_event_link',10,4);

/*
 * Translate the Title in the event calendar
 * from divi-event-calendar-module/divi-event-calendar-module.php 574
 * $e["title"]='<a class="'.$disable_event_calendar_title_link.'" href="'.$e['custom_event_link_url'].'" target="'.$custom_event_link_target.'">'.$event->post_title .'</a>';
 * use apply_filter
 * */
function falang_tribe_get_event_cm_title( $title, $event ) {
  if (isset($_REQUEST['locale'])){
    //locale on page don't have the right format
    $locale = str_replace("-","_",$_REQUEST['locale']);
    $language = Falang()->get_model()->get_language_by_locale($locale);
    if (isset($language) && $event){
      $falang_post = new \Falang\Core\Post();
      $title = $falang_post->translate_post_field($event, 'post_title', $language);
    }
  }
  return $title;
}

add_filter('tribe_get_event_cm_title','falang_tribe_get_event_cm_title',10,2);

Divi