French Dates and Times

Home Forums Additional Help Translations French Dates and Times

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1113398
    pwnhcca
    Participant

    I have had to tweak the core code of The Events Calendar and Events Calendar Pro to get French dates on a WPML bilingual enabled website to display properly. Here’s what I did, and I want to know if there is an easier less hacky way to do this (I have to remember to copy over the files whenever the events calendar is updated).

    In theeventscalendar/src/functions/template-tags/general.php:

    Modify function tribe_get_event_categories:

    
    			if (ICL_LANGUAGE_CODE == 'fr') {
    				$label = sprintf(
    					_nx( 'Catégorie d’événements ', 'Catégories d’événements ', substr_count( $categories, '<a href' ), 'taxonomie', 'the-events-calendar' ),
    					$events_label_singular
    				); }
    			else {
    
    				$label = sprintf(
    					_nx( '%s Category', '%s Categories', substr_count( $categories, '<a href' ), 'category list label', 'the-events-calendar' ),
    					$events_label_singular
    				);
    			}

    Modify function tribe_events_event_schedule_details:

    		$time_format = tribe_get_time_format(); 
    
    		if (ICL_LANGUAGE_CODE == 'fr') {
    			$datetime_separator = ', de ';
    			$time_range_separator = ' à ';
    		} else {
    			$datetime_separator = tribe_get_option( 'dateTimeSeparator', ', ' );
    			$time_range_separator = tribe_get_option( 'timeRangeSeparator', ' - ' );
    		}
    

    In theeventscalendar/common/src/functions/template-tags/general.php:

    Modify function tribe_get_date_format:

    if (ICL_LANGUAGE_CODE == 'fr') {
    				if ( $with_year ) {
    					$format = 'j F Y';
    					} else {
    					$format = 'j F';
    					}  
    				} else {
    					if ( $with_year ) {
    					$format = tribe_get_option( 'dateWithYearFormat', get_option( 'date_format' ) );
    					} else {
    					$format = tribe_get_option( 'dateWithoutYearFormat', 'F j' );
    				}
    			}

    Modify function tribe_get_datetime_format:

    if (ICL_LANGUAGE_CODE == 'fr') {
    				$separator = (array) str_split( tribe_get_option( 'dateTimeSeparator', ', ' ) );
    				$format = 'j F';
    				$format .= ( ! empty( $separator ) ? '\\' : '' ) . implode( '\\', $separator );
    				$format .= 'G \h i';
    			} else {
    				$separator = (array) str_split( tribe_get_option( 'dateTimeSeparator', ', ' ) );
    				$format = tribe_get_date_format( $with_year );
    				$format .= ( ! empty( $separator ) ? '\\' : '' ) . implode( '\\', $separator );
    				$format .= get_option( 'time_format' );
    			}

    Modify function tribe_get_time_format( ):

    if (ICL_LANGUAGE_CODE == 'fr') {
    				$format = 'G \h i';
    			} else {
    				$format = get_option( 'time_format' );
    			}

    In theeventscalendar/src/views/modules/meta/details.php:

    Replace get_option( ‘time_format’ ); with:

    $time_format = tribe_get_time_format(); 
    
    if (ICL_LANGUAGE_CODE == 'fr') {
    	$time_range_separator = ' à ';
    } else {
    	$time_range_separator = tribe_get_option( 'timeRangeSeparator', ' - ' );
    }
    

    The last file can be moved to my child theme folder, but the general template-tag files cannot.

    • This topic was modified 7 years, 11 months ago by pwnhcca.
    • This topic was modified 7 years, 11 months ago by pwnhcca.
    #1113498
    Geoff B.
    Member

    Good evening Rajiv and welcome back!

    Thank you for reaching out to us.
    I would love to help you with this topic.

    The short answer to your question is that you should not have to modify any piece of code to get the dates to display properly in French while using WPML with our products.
    I know that for a fact since I am a big WPML user myself.

    My first question would be, did you follow the knowledge base articles found here ? https://theeventscalendar.com/?s=wpml&submit=Search&post_type%5B%5D=documentation&post_type%5B%5D=tribe-knowledgebase

    As a first troubleshooting step, could you please provide us with your complete system information in a private reply using the instructions found in the following link?

    https://theeventscalendar.com/knowledgebase/sharing-sys-info/

    Best regards,

    Geoff B.

    #1113950
    pwnhcca
    Participant

    The issue is that French is very particular with its time and dating system, given than even the separators are different (and sometimes they want the article in front of the day, as in le 6 mai, de 12 h à 4 h 30). Indeed, in the above code, I still have to put in a conditional to omit the zeroes if the time is at the hour mark. I don’t think even php’s date localization can do this out of the box, but could be wrong.

    But definitely where the following appears:

    $time_format = get_option( ‘time_format’ );

    should be replaced with:

    $time_format = tribe_get_time_format();

    Also, I can’t seem to see the mark reply as private option?

    • This reply was modified 7 years, 11 months ago by pwnhcca.
    #1114135
    Geoff B.
    Member

    Hello Rajiv,

    As it turns out I am actually French. So I understand very well the differences in both the time and date formats.
    In fact, we can continue that conversation in French if you prefer.

    That being said, both WPML and our plugins should be able to handle that difference in format without touching the core code.
    Here’s what I am talking about: https://wpml.org/forums/topic/date-formatting-issue/

    Where you do have a point is if you are looking to take this the extra step (by removing the zero from 12 h for example).
    Even WordPress does not go that far in it’s french time format support. But it’s pretty cool that you are doing just that, but I would still recommend doing so through the functions.php file of your WordPress theme.

    Let me know if that helps.

    Have a great day!

    Geoff B.

    p.s.: there is no private reply option (my bad), because this is in the translation forum as opposed to the premium support forum.

    #1119785
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘French Dates and Times’ is closed to new replies.