load_script_module_textdomain()
Loads the translation data for a given script module ID and text domain.
Works like load_script_textdomain() but for script modules registered via wp_register_script_module().
No Hooks.
Returns
String|false. The JSON-encoded translated strings for the given script module and text domain. False if there are none.
Usage
load_script_module_textdomain( $id, $domain, $path );
- $id(string) (required)
- The script module identifier.
- $domain(string)
- Text domain.
Default:'default' - $path(string)
- The full file path to the directory containing translation files.
Default:''
Changelog
| Since 7.0.0 | Introduced. |
load_script_module_textdomain() load script module textdomain code WP 7.0
function load_script_module_textdomain( string $id, string $domain = 'default', string $path = '' ) {
$module = wp_script_modules()->get_registered( $id );
if ( null === $module ) {
return false;
}
$src = $module['src'];
// Ensure src is an absolute URL for path resolution.
if ( ! preg_match( '|^(https?:)?//|', $src ) ) {
$src = site_url( $src );
}
return _load_script_textdomain_from_src( $id, $src, $domain, $path, true );
}