Localize a script.

Works only if the script has already been added.

Accepts an associative array $l10n and creates a JavaScript object: "$object_name" = key: value, key: value, ...

Signature

wp_localize_script( $handle, $object_name, $l10n )
handle
 (string) Script handle the data will be attached to.
object_name
 (string) Name for the JavaScript object. Passed directly, so it should be qualified JS variable. Example: '/[a-zA-Z0-9_]+/'.
l10n
 (array) The data itself. The data can be either a single or multi-dimensional array.

Return

(boolean) True if the script was successfully localized, false otherwise.

Source

function wp_localize_script( $handle, $object_name, $l10n ) {
	global $wp_scripts;
	if ( ! is_a( $wp_scripts, 'WP_Scripts' ) ) {
		if ( ! did_action( 'init' ) )
			_doing_it_wrong( __FUNCTION__, sprintf( __( 'Scripts and styles should not be registered or enqueued until the %1$s, %2$s, or %3$s hooks.' ),
				'<code>wp_enqueue_scripts</code>', '<code>admin_enqueue_scripts</code>', '<code>login_enqueue_scripts</code>' ), '3.3' );

		return false;
	}

	return $wp_scripts->localize( $handle, $object_name, $l10n );
}
WP Trac GitHub

Link here