English (United Kingdom)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  Reservation  >  Translate Details

apply_filters( 'vikrestaurants_translate_restaurant_reservation_details', bool $status, object $reservation, string $langtag )

Fires while translating the details of the restaurant reservation into a specific language.


Description

External plugins can use this event to apply the translations to additional details manually included within the reservation object.

Since the query used to load the details can be extended, this method offers the possibility to translate any additional data in the right way.


Parameters

$status

(bool)  True on success, false otherwise.

$reservation

(object)  The object holding the details of the reservation.

$langtag

(string)  The language tag.


Example

The example below explains how the internal translation system works.

/**
 * External plugins can use this event to apply the translations to
 * additional details manually included within the reservation object.
 *
 * @param   boolean  $status       True on success, false otherwise.
 * @param   object   $reservation  The reservation details object.
 * @param   string   $langtag      The requested language tag.
 */
add_filter('vikrestaurants_translate_restaurant_reservation_details', function($status, $reservation, $langtag)
{
    // get translator
    $translator = VREFactory::getTranslator();

    // The products translation is already handled by the system, this is
    // just an explanation of how the translation system works.

    foreach ($reservation->items as &$item)
    {
        // translate product
        $tx = $translator->translate('menusproduct', $item->id, $langtag);

        if ($tx)
        {
            // inject translation within item details
            $item->productName = $tx->name;
        }
    }

    return true;
}, 10, 3);

Changelog

Version Description
1.2.1 Introduced.
Last Update: 2021-03-03
Helpful?
See Also: