Make WordPress Core


Ignore:
Timestamp:
09/17/2024 08:56:03 PM (18 months ago)
Author:
swissspidy
Message:

I18N: Add a new way to determine whether a translation is available.

A new has_translation() function can be used to determine whether a translation exists for a given string.

Props louiswol94, swissspidy, drzraf, ckanitz, tomhine, mchirag2002, samuelsilvapt.
Fixes #52696.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/l10n.php

    r58095 r59029  
    19891989    return $wp_locale->get_word_count_type();
    19901990}
     1991
     1992/**
     1993 * Returns a boolean to indicate whether a translation exists for a given string with optional text domain and locale.
     1994 *
     1995 * @since 6.7.0
     1996 *
     1997 * @param string  $singular   Singular translation to check.
     1998 * @param string  $textdomain Optional. Text domain. Default 'default'.
     1999 * @param ?string $locale     Optional. Locale. Default current locale.
     2000 * @return bool  True if the translation exists, false otherwise.
     2001 */
     2002function has_translation( string $singular, string $textdomain = 'default', ?string $locale = null ): bool {
     2003    return WP_Translation_Controller::get_instance()->has_translation( $singular, $textdomain, $locale );
     2004}
Note: See TracChangeset for help on using the changeset viewer.