How to Translate Availability Search

We want to make translating easy, therefore we are building multiple ways to translate Availability Search for WooCommerce Bookings. Note that we currently only support translations of all frontend/customer displayed text. Our settings pages are still in English.

Using WPML or Loco Translate

If you need to translate Availability Search for WooCommerce Bookings into any language, then you can use your favorite WordPress translation plugin. Availability Search is compatible with plugins like WPML – The WordPress Multilingual Plugin or a free plugin like Loco Translate, just search for strings to translate under the text-domain ‘availability-search-for-woocommerce-bookings’.

Translate using a custom filter snippet

If you want to use a custom filter to translate the date picker and  strings, then we recommend you use the below example. Just change the the strings to your language, then copy the whole snippet into your child themes’s funtions.php file, or a custom plugin. That’s it! just double check that the translations is working.

function aswb_filter_translations_example( $translations ) {

	$translations = array(

		'separator'   => __( ' to ', 'availability-search-for-woocommerce-bookings' ),
		'applyLabel'  => __( 'Apply', 'availability-search-for-woocommerce-bookings' ),
		'cancelLabel' => __( 'Cancel', 'availability-search-for-woocommerce-bookings' ),
		'fromLabel'   => __( 'From', 'availability-search-for-woocommerce-bookings' ),
		'toLabel'     => _x( 'To', 'seperator between dates', 'availability-search-for-woocommerce-bookings' ),

		'sunday'      => _x( 'Su', 'Sunday, short version', 'availability-search-for-woocommerce-bookings' ),
		'monday'      => _x( 'Mo', 'Monday, short version', 'availability-search-for-woocommerce-bookings' ),
		'tuesday'     => _x( 'Tu', 'Tuesday, short version', 'availability-search-for-woocommerce-bookings' ),
		'wednesday'   => _x( 'We', 'Wednesday, short version', 'availability-search-for-woocommerce-bookings' ),
		'thursday'    => _x( 'Th', 'Thursay, short version', 'availability-search-for-woocommerce-bookings' ),
		'friday'      => _x( 'Fr', 'Friday, short version', 'availability-search-for-woocommerce-bookings' ),
		'saturday'    => _x( 'Sa', 'Saturday, short version', 'availability-search-for-woocommerce-bookings' ),

		'january'     => __( 'January', 'availability-search-for-woocommerce-bookings' ),
		'february'    => __( 'February', 'availability-search-for-woocommerce-bookings' ),
		'march'       => __( 'March', 'availability-search-for-woocommerce-bookings' ),
		'april'       => __( 'April', 'availability-search-for-woocommerce-bookings' ),
		'may'         => __( 'May', 'availability-search-for-woocommerce-bookings' ),
		'june'        => __( 'June', 'availability-search-for-woocommerce-bookings' ),
		'july'        => __( 'July', 'availability-search-for-woocommerce-bookings' ),
		'august'      => __( 'August', 'availability-search-for-woocommerce-bookings' ),
		'september'   => __( 'September', 'availability-search-for-woocommerce-bookings' ),
		'october'     => __( 'October', 'availability-search-for-woocommerce-bookings' ),
		'november'    => __( 'November', 'availability-search-for-woocommerce-bookings' ),
		'december'    => __( 'December', 'availability-search-for-woocommerce-bookings' ),
	);

	return $translations;

}
add_filter( 'aswb_filter_translations', 'aswb_filter_translations_example', 10, 3 );Code language: PHP (php)

Translate Error Messages

There is currently one error message that customers will see. The error only displays if there is no products available for their search. You can customise or just translate it using the below filter.

function aswb_error_message_translated( $error_message ) {

 $error_message = 'No products match your selected dates, try searching for another date range';

  return $error_message;
}
add_filter( 'aswb_filter_error_messages', 'aswb_error_message_translated' );Code language: PHP (php)

Translate filter labels

/**
 * Override the default lables around Availability Search.
 *
 * @param array $labels
 * @return array $labels
 */
function custom_aswb_search_label( $labels ) {

	$labels['taxonomy_default'] = 'Show Any';
	$labels['category_default'] = 'Show Any';
	$labels['categories'] = 'Categories';
	$labels['datepicker'] = 'Choose Dates';
	$labels['keyword'] = 'Search by Name';
	$labels['keyword_placeholder'] = 'Name';

	return $labels;
}

add_filter( 'aswb_filter_search_strings', 'custom_aswb_search_label', 10, 1 );
Code language: PHP (php)
Was this page helpful?