Automattic\WooCommerce\Internal\Admin
Translations::load_script_translation_file
Load translation strings from language packs for dynamic imports.
Method of the class: Translations{}
No Hooks.
Returns
string. New file location for the script being translated.
Usage
$Translations = new Translations(); $Translations->load_script_translation_file( $file, $handle, $domain );
- $file(string) (required)
- File location for the script being translated.
- $handle(string) (required)
- Script handle.
- $domain(string) (required)
- Text domain.
Translations::load_script_translation_file() Translations::load script translation file code WC 11.3.0
public function load_script_translation_file( $file, $handle, $domain ) {
// Make sure the main app script is being loaded.
if ( WC_ADMIN_APP !== $handle ) {
return $file;
}
// Make sure we're handing the correct domain.
if ( self::$plugin_domain !== $domain ) {
return $file;
}
$locale = determine_locale();
$cache_filename = $this->get_combined_translation_filename( $domain, $locale );
$cache_path = WP_LANG_DIR . '/plugins/' . $cache_filename;
// Rebuild the combined file on demand, since it is only generated on language pack updates and plugin activation.
if ( ! is_readable( $cache_path ) && ! $this->regeneration_attempted ) {
$this->regeneration_attempted = true;
$this->generate_translation_strings();
}
// Fall back so the app's own translation file still loads.
if ( ! is_readable( $cache_path ) ) {
return $file;
}
return $cache_path;
}