: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* The dynamic portion of the hook name, `$domain`, refers to the text domain.
* @param string $translation Translated text.
* @param string $single The text to be used if the number is singular.
* @param string $plural The text to be used if the number is plural.
* @param int $number The number to compare against to use either the singular or plural form.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
$translation = apply_filters( "ngettext_{$domain}", $translation, $single, $plural, $number, $domain );
* Translates and retrieves the singular or plural form based on the supplied number, with gettext context.
* This is a hybrid of _n() and _x(). It supports context and plurals.
* Used when you want to use the appropriate form of a string with context based on whether a
* number is singular or plural.
* Example of a generic phrase which is disambiguated via the context parameter:
* printf( _nx( '%s group', '%s groups', $people, 'group of people', 'text-domain' ), number_format_i18n( $people ) );
* printf( _nx( '%s group', '%s groups', $animals, 'group of animals', 'text-domain' ), number_format_i18n( $animals ) );
* @since 5.5.0 Introduced `ngettext_with_context-{$domain}` filter.
* @param string $single The text to be used if the number is singular.
* @param string $plural The text to be used if the number is plural.
* @param int $number The number to compare against to use either the singular or plural form.
* @param string $context Context information for the translators.
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
* @return string The translated singular or plural form.
function _nx( $single, $plural, $number, $context, $domain = 'default' ) {
$translations = get_translations_for_domain( $domain );
$translation = $translations->translate_plural( $single, $plural, $number, $context );
* Filters the singular or plural form of a string with gettext context.
* @param string $translation Translated text.
* @param string $single The text to be used if the number is singular.
* @param string $plural The text to be used if the number is plural.
* @param int $number The number to compare against to use either the singular or plural form.
* @param string $context Context information for the translators.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
$translation = apply_filters( 'ngettext_with_context', $translation, $single, $plural, $number, $context, $domain );
* Filters the singular or plural form of a string with gettext context for a domain.
* The dynamic portion of the hook name, `$domain`, refers to the text domain.
* @param string $translation Translated text.
* @param string $single The text to be used if the number is singular.
* @param string $plural The text to be used if the number is plural.
* @param int $number The number to compare against to use either the singular or plural form.
* @param string $context Context information for the translators.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
$translation = apply_filters( "ngettext_with_context_{$domain}", $translation, $single, $plural, $number, $context, $domain );
* Registers plural strings in POT file, but does not translate them.
* Used when you want to keep structures with translatable plural
* strings and use them later when the number is known.
* $message = _n_noop( '%s post', '%s posts', 'text-domain' );
* printf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) );
* @param string $singular Singular form to be localized.
* @param string $plural Plural form to be localized.
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
* Array of translation information for the strings.
* @type string $0 Singular form to be localized. No longer used.
* @type string $1 Plural form to be localized. No longer used.
* @type string $singular Singular form to be localized.
* @type string $plural Plural form to be localized.
* @type null $context Context information for the translators.
* @type string|null $domain Text domain.
function _n_noop( $singular, $plural, $domain = null ) {
* Registers plural strings with gettext context in POT file, but does not translate them.
* Used when you want to keep structures with translatable plural
* strings and use them later when the number is known.
* Example of a generic phrase which is disambiguated via the context parameter:
* 'people' => _nx_noop( '%s group', '%s groups', 'people', 'text-domain' ),
* 'animals' => _nx_noop( '%s group', '%s groups', 'animals', 'text-domain' ),
* $message = $messages[ $type ];
* printf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) );
* @param string $singular Singular form to be localized.
* @param string $plural Plural form to be localized.
* @param string $context Context information for the translators.
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
* Array of translation information for the strings.
* @type string $0 Singular form to be localized. No longer used.
* @type string $1 Plural form to be localized. No longer used.
* @type string $2 Context information for the translators. No longer used.
* @type string $singular Singular form to be localized.
* @type string $plural Plural form to be localized.
* @type string $context Context information for the translators.
* @type string|null $domain Text domain.
function _nx_noop( $singular, $plural, $context, $domain = null ) {
* Translates and returns the singular or plural form of a string that's been registered
* with _n_noop() or _nx_noop().
* Used when you want to use a translatable plural string once the number is known.
* $message = _n_noop( '%s post', '%s posts', 'text-domain' );
* printf( translate_nooped_plural( $message, $count, 'text-domain' ), number_format_i18n( $count ) );
* @param array $nooped_plural {
* Array that is usually a return value from _n_noop() or _nx_noop().
* @type string $singular Singular form to be localized.
* @type string $plural Plural form to be localized.
* @type string|null $context Context information for the translators.
* @type string|null $domain Text domain.
* @param int $count Number of objects.
* @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings. If $nooped_plural contains
* a text domain passed to _n_noop() or _nx_noop(), it will override this value. Default 'default'.
* @return string Either $singular or $plural translated text.
function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) {
if ( $nooped_plural['domain'] ) {
$domain = $nooped_plural['domain'];
if ( $nooped_plural['context'] ) {
return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain );
return _n( $nooped_plural['singular'], $nooped_plural['plural'], $count, $domain );
* Loads a .mo file into the text domain $domain.
* If the text domain already exists, the translations will be merged. If both
* sets have the same string, the translation from the original value will be taken.
* On success, the .mo file will be placed in the $l10n global by $domain
* and will be a MO object.
* @since 6.1.0 Added the `$locale` parameter.
* @global MO[] $l10n An array of all currently loaded text domains.
* @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again.
* @global WP_Textdomain_Registry $wp_textdomain_registry WordPress Textdomain Registry.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @param string $mofile Path to the .mo file.
* @param string $locale Optional. Locale. Default is the current locale.
* @return bool True on success, false on failure.
function load_textdomain( $domain, $mofile, $locale = null ) {
/** @var WP_Textdomain_Registry $wp_textdomain_registry */
global $l10n, $l10n_unloaded, $wp_textdomain_registry;
$l10n_unloaded = (array) $l10n_unloaded;
if ( ! is_string( $domain ) ) {
* Filters whether to short-circuit loading .mo file.
* Returning a non-null value from the filter will effectively short-circuit
* the loading, returning the passed value instead.
* @param bool|null $loaded The result of loading a .mo file. Default null.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @param string $mofile Path to the MO file.
* @param string|null $locale Locale.
$loaded = apply_filters( 'pre_load_textdomain', null, $domain, $mofile, $locale );
if ( null !== $loaded ) {
if ( true === $loaded ) {
unset( $l10n_unloaded[ $domain ] );
* Filters whether to override the .mo file loading.
* @since 6.2.0 Added the `$locale` parameter.
* @param bool $override Whether to override the .mo file loading. Default false.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @param string $mofile Path to the MO file.
* @param string|null $locale Locale.
$plugin_override = apply_filters( 'override_load_textdomain', false, $domain, $mofile, $locale );
if ( true === (bool) $plugin_override ) {
unset( $l10n_unloaded[ $domain ] );
* Fires before the MO translation file is loaded.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @param string $mofile Path to the .mo file.
do_action( 'load_textdomain', $domain, $mofile );
* Filters MO file path for loading translations for a specific text domain.
* @param string $mofile Path to the MO file.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
$mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain );
$locale = determine_locale();
$i18n_controller = WP_Translation_Controller::get_instance();
// Ensures the correct locale is set as the current one, in case it was filtered.
$i18n_controller->set_locale( $locale );
* Filters the preferred file format for translation files.
* Can be used to disable the use of PHP files for translations.
* @param string $preferred_format Preferred file format. Possible values: 'php', 'mo'. Default: 'php'.
* @param string $domain The text domain.
$preferred_format = apply_filters( 'translation_file_format', 'php', $domain );
if ( ! in_array( $preferred_format, array( 'php', 'mo' ), true ) ) {
$preferred_format = 'php';
$translation_files = array();
if ( 'mo' !== $preferred_format ) {
$translation_files[] = substr_replace( $mofile, ".l10n.$preferred_format", - strlen( '.mo' ) );
$translation_files[] = $mofile;
foreach ( $translation_files as $file ) {
* Filters the file path for loading translations for the given text domain.
* Similar to the {@see 'load_textdomain_mofile'} filter with the difference that
* the file path could be for an MO or PHP file.
* @since 6.6.0 Added the `$locale` parameter.
* @param string $file Path to the translation file to load.
* @param string $domain The text domain.
* @param string $locale The locale.
$file = (string) apply_filters( 'load_translation_file', $file, $domain, $locale );
$success = $i18n_controller->load_file( $file, $domain, $locale );
if ( isset( $l10n[ $domain ] ) && $l10n[ $domain ] instanceof MO ) {
$i18n_controller->load_file( $l10n[ $domain ]->get_filename(), $domain, $locale );
// Unset NOOP_Translations reference in get_translations_for_domain().
unset( $l10n[ $domain ] );
$l10n[ $domain ] = new WP_Translations( $i18n_controller, $domain );
$wp_textdomain_registry->set( $domain, $locale, dirname( $file ) );
* Unloads translations for a text domain.
* @since 6.1.0 Added the `$reloadable` parameter.
* @global MO[] $l10n An array of all currently loaded text domains.
* @global MO[] $l10n_unloaded An array of all text domains that have been unloaded again.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @param bool $reloadable Whether the text domain can be loaded just-in-time again.
* @return bool Whether textdomain was unloaded.
function unload_textdomain( $domain, $reloadable = false ) {
global $l10n, $l10n_unloaded;
$l10n_unloaded = (array) $l10n_unloaded;
* Filters whether to override the text domain unloading.
* @since 6.1.0 Added the `$reloadable` parameter.
* @param bool $override Whether to override the text domain unloading. Default false.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @param bool $reloadable Whether the text domain can be loaded just-in-time again.
$plugin_override = apply_filters( 'override_unload_textdomain', false, $domain, $reloadable );
if ( $plugin_override ) {
$l10n_unloaded[ $domain ] = true;
* Fires before the text domain is unloaded.
* @since 6.1.0 Added the `$reloadable` parameter.
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
* @param bool $reloadable Whether the text domain can be loaded just-in-time again.
do_action( 'unload_textdomain', $domain, $reloadable );
// Since multiple locales are supported, reloadable text domains don't actually need to be unloaded.
WP_Translation_Controller::get_instance()->unload_textdomain( $domain );
if ( isset( $l10n[ $domain ] ) ) {
if ( $l10n[ $domain ] instanceof NOOP_Translations ) {
unset( $l10n[ $domain ] );
unset( $l10n[ $domain ] );
$l10n_unloaded[ $domain ] = true;
* Loads default translated strings based on locale.
* Loads the .mo file in WP_LANG_DIR constant path from WordPress root.
* The translated (.mo) file is named based on the locale.
* @param string $locale Optional. Locale to load. Default is the value of get_locale().
* @return bool Whether the textdomain was loaded.
function load_default_textdomain( $locale = null ) {
if ( null === $locale ) {
$locale = determine_locale();
// Unload previously loaded strings so we can switch translations.
unload_textdomain( 'default', true );
$return = load_textdomain( 'default', WP_LANG_DIR . "/$locale.mo", $locale );
if ( ( is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) && ! file_exists( WP_LANG_DIR . "/admin-$locale.mo" ) ) {
load_textdomain( 'default', WP_LANG_DIR . "/ms-$locale.mo", $locale );
if ( is_admin() || wp_installing() || ( defined( 'WP_REPAIRING' ) && WP_REPAIRING ) ) {
load_textdomain( 'default', WP_LANG_DIR . "/admin-$locale.mo", $locale );
if ( is_network_admin() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK ) ) {
load_textdomain( 'default', WP_LANG_DIR . "/admin-network-$locale.mo", $locale );
* Loads a plugin's translated strings.
* If the path is not given then it will be the root of the plugin directory.
* The .mo file should be named based on the text domain with a dash, and then the locale exactly.
* @since 4.6.0 The function now tries to load the .mo file from the languages directory first.
* @param string $domain Unique identifier for retrieving translated strings
* @param string|false $deprecated Optional. Deprecated. Use the $plugin_rel_path parameter instead.
* @param string|false $plugin_rel_path Optional. Relative path to WP_PLUGIN_DIR where the .mo file resides.
* @return bool True when textdomain is successfully loaded, false otherwise.
function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path = false ) {
/** @var WP_Textdomain_Registry $wp_textdomain_registry */
global $wp_textdomain_registry;
if ( ! is_string( $domain ) ) {