diff --git a/wp-includes/l10n.php b/wp-includes/l10n.php index 038b916049..1f3532a40d 100644 --- a/wp-includes/l10n.php +++ b/wp-includes/l10n.php @@ -1988,3 +1988,17 @@ function wp_get_word_count_type() { return $wp_locale->get_word_count_type(); } + +/** + * Returns a boolean to indicate whether a translation exists for a given string with optional text domain and locale. + * + * @since 6.7.0 + * + * @param string $singular Singular translation to check. + * @param string $textdomain Optional. Text domain. Default 'default'. + * @param ?string $locale Optional. Locale. Default current locale. + * @return bool True if the translation exists, false otherwise. + */ +function has_translation( string $singular, string $textdomain = 'default', ?string $locale = null ): bool { + return WP_Translation_Controller::get_instance()->has_translation( $singular, $textdomain, $locale ); +} diff --git a/wp-includes/l10n/class-wp-translation-controller.php b/wp-includes/l10n/class-wp-translation-controller.php index 295e3fcac7..c68cf32add 100644 --- a/wp-includes/l10n/class-wp-translation-controller.php +++ b/wp-includes/l10n/class-wp-translation-controller.php @@ -434,4 +434,22 @@ final class WP_Translation_Controller { return $this->loaded_translations[ $locale ][ $textdomain ] ?? array(); } + + /** + * Returns a boolean to indicate whether a translation exists for a given string with optional text domain and locale. + * + * @since 6.7.0 + * + * @param string $singular Singular translation to check. + * @param string $textdomain Optional. Text domain. Default 'default'. + * @param ?string $locale Optional. Locale. Default current locale. + * @return bool True if the translation exists, false otherwise. + */ + public function has_translation( string $singular, string $textdomain = 'default', ?string $locale = null ): bool { + if ( null === $locale ) { + $locale = $this->current_locale; + } + + return false !== $this->locate_translation( $singular, $textdomain, $locale ); + } } diff --git a/wp-includes/version.php b/wp-includes/version.php index 5e802961e7..ea579c8f67 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.7-alpha-59028'; +$wp_version = '6.7-alpha-59029'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.