WP_Scripts::set_translations() WordPress Method

The WP_Scripts::set_translations() method allows you to set the translations for a script. This is useful if you need to override the default translation for a script.

WP_Scripts::set_translations( string $handle, string $domain = 'default', string $path = null ) #

Sets a translation textdomain.


Parameters

$handle

(string)(Required)Name of the script to register a translation domain to.

$domain

(string)(Optional) Text domain.

Default value: 'default'

$path

(string)(Optional) The full file path to the directory containing translation files.

Default value: null


Top ↑

Return

(bool) True if the text domain was registered, false if not.


Top ↑

Source

File: wp-includes/class.wp-scripts.php

	public function set_translations( $handle, $domain = 'default', $path = null ) {
		if ( ! isset( $this->registered[ $handle ] ) ) {
			return false;
		}

		/** @var \_WP_Dependency $obj */
		$obj = $this->registered[ $handle ];

		if ( ! in_array( 'wp-i18n', $obj->deps, true ) ) {
			$obj->deps[] = 'wp-i18n';
		}

		return $obj->set_translations( $domain, $path );
	}


Top ↑

Changelog

Changelog
VersionDescription
5.1.0The $domain parameter was made optional.
5.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.