SportsPress icon indicating copy to clipboard operation
SportsPress copied to clipboard

Add Datatable string `emptyTable` to `localized_strings`

Open kadimi opened this issue 3 years ago • 0 comments

This allows us to customize the text shown when the table is empty:

Here's the PHP code for overriding that text assuming this pull request is merged.

 /**
  * Override some SportsPress translations
  *
  * - 'No matching records found' => 'Schedules Will Be Uploaded Shortly'
  */
add_filter( 'gettext', function( $translation, $text, $domain ) {
	$overrides = [
		'No matching records found' => 'Schedules Will Be Uploaded Shortly',
	];

	/**
	 * Should we override?
	 *
	 * - Domain is SportsPress
	 * - Locale is en_US
	 * - String is in the overrides table
	 */
	$should_override = ( true
		&& 'sportspress' === $domain
		&& 'en_US' ===  get_locale()
		&& array_key_exists( $text, $overrides )
	);

	return $should_override
		? $overrides[ $text ]
		: $translation
	;
}, 10, 3 );

kadimi avatar Sep 28 '21 15:09 kadimi