WP_Script_Modules::set_translations
Overrides the text domain and path used to load translations for a script module.
This is only needed for modules whose text domain differs from 'default' or whose translation files live outside the standard locations, for example plugin modules that register their own text domain. Translations for modules that use the default domain are loaded automatically by WP_Script_Modules::print_script_module_translations().
Method of the class: WP_Script_Modules{}
No Hooks.
Returns
true|false. True if the text domain was registered, false if the module is not registered.
Usage
$WP_Script_Modules = new WP_Script_Modules(); $WP_Script_Modules->set_translations( $id, $domain, $path ): bool;
- $id(string) (required)
- The identifier of the script module.
- $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. |
WP_Script_Modules::set_translations() WP Script Modules::set translations code WP 7.0
public function set_translations( string $id, string $domain = 'default', string $path = '' ): bool {
if ( ! isset( $this->registered[ $id ] ) ) {
return false;
}
$this->registered[ $id ]['textdomain'] = $domain;
$this->registered[ $id ]['translations_path'] = $path;
return true;
}