• Resolved Daedalon

    (@daedalon)


    The easiest and most update-safe way to add support for qTranslate in placeholders should be via a filter. However, it seems that I haven’t yet found the correct filters to hook into so that #_EVENTLINK and #_EVENTCATEGORIES would also get translated correctly. I tried the following in a customization plugin:

    // Add qTranslate support for event and location placeholders
    function qtrans_em_output_placeholder( $replace /*, $this, $full_result, $target */ ) {
    	$replace = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $replace );
    	return $replace ;
    }
    if ( function_exists( 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage' ) ) {
    	add_filter( 'em_event_output_placeholder', 'qtrans_em_output_placeholder', 20, 3 );
    	add_filter( 'em_location_output_placeholder', 'qtrans_em_output_placeholder', 20, 3 );
    }

    So far we’ve had the support done via custom placeholders, but that’s not update-safe as updates to placeholder handling in core don’t get reflected automatically. What’s the correct way to add update-safe qTranslate support for #_EVENTLINK, #_EVENTCATEGORIES and all the other placeholders?

    http://wordpress.org/extend/plugins/events-manager/

Viewing 7 replies - 1 through 7 (of 7 total)
  • try to use hooks/filters and then add it in your theme functions.php e.g. http://wp-events-plugin.com/tutorials/modifying-placeholder-default-information/

    Thread Starter Daedalon

    (@daedalon)

    The above code is using filters, so something else is amiss. The location filter is the same as in your link, but still location names are displayed as “<!–:en–>Location Name<!–:–><!–:fi–>Paikan nimi<!–:–>” instead of “Location Name” or “Paikan nimi”.

    The above code is in a plugin. Can’t test right now, but would it make a difference if it was in theme’s functions.php?

    Plugin Author Marcus (aka @msykes)

    (@netweblogic)

    i’m not sure… would have to test qtranslate to figure this out and no time for that atm.

    i think it’d be to do with your odering of filters, e.g. qtransalte hasn’t figured out the language it’s in at that time.

    Thread Starter Daedalon

    (@daedalon)

    That qTranslate function uses default language when unsure. That code kicks in for some shortcodes, for example as #_EVENTNAME. The only non-affected shortcodes seem to be #_EVENTLINK, #_EVENTCATEGORIES and #_LOCATIONLINK. What they have in common is that they return HTML instead of a plain, translatable string.

    Is there a way to make $EM_Event and $EM_Location objects apply filters to all their values upon creation? That way $location_name = $EM_Location->location_name; would always result in a string in a correct language.

    agelonwl

    (@angelonwl)

    yes, you can try to override placeholder ? http://wp-events-plugin.com/tutorials/modifying-placeholder-default-information/

    e.g.

    add_filter('em_location_output_placeholder','my_em_placeholder_mod',1,3);
    function my_em_placeholder_mod($replace, $EM_Location, $result){
    	if ( $result == '#_LOCATIONNAME' ) {
    		$replace = $EM_Location->location_name;
    	}
    	return $replace;
    }

    *paste in your theme functions.php

    Thread Starter Daedalon

    (@daedalon)

    That’s what we’re doing at the moment. We’re looking forward to a more update-safe solution by filters and hooks that complement the core placeholders instead of overriding them.

    An option that crossed my mind is whether it’d be feasible to make placeholders in core recursive for one level so they would work like this:

    1. #_EVENTLINK is called
    2. The appropriate placeholder rule is triggered via filter em_event_output_placeholder
    3. That placeholder calls for #_EVENTNAME, which triggers the appropriate placeholder rule via filter em_event_output_placeholder

    This would sound to me like the most suitable way to contain the same functionality within placeholders. #_EVENTNAME and #_EVENTLINK then use the same line of code to retrieve the name of the event, so that any changes to it don’t need to be done in any other part of the code.

    The ability to catch every placeholder via filters for multilinguality could be considered one of the best side effects.

    Thread Starter Daedalon

    (@daedalon)

    I might have found what I was looking for. Testing continues, but so far it seems to me that everywhere where the site displays an event, filter ’em_get_event’ is called. The following adds qTranslate support for event names everywhere that I tested, with the exception for emails.

    // qTranslate support for event names everywhere on the site 2013-06-11
    // TODO: Notification email support
    add_filter( 'em_get_event', 'my_em_get_event_qtrans', 10 );
    function my_em_get_event_qtrans( $event ) {
    	if( function_exists( 'qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage' ) ) {
    			$event->event_name = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $event->event_name );
    	}
    	return $event;
    }

    Next I’m looking into the option of hooking on to line 267 in classes/em-event.php‘s __construct() in the hopes of multilingualizing event names everywhere, including emails:

    do_action('em_event', $this, $id, $search_by);

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Adding update-safe qTranslate support’ is closed to new replies.