id;
$is_woocommerce_page =
property_exists( $current_screen, 'parent_base' ) &&
'woocommerce' === $current_screen->parent_base;
return $is_plugins_page || $is_woocommerce_page;
}
if ( version_compare( $GLOBALS['wp_version'], $minimum_wp_version, '<' ) ) {
/**
* Outputs for an admin notice about running WooCommerce Blocks on outdated WordPress.
*
* @since 2.5.0
*/
function woocommerce_blocks_admin_unsupported_wp_notice() {
if ( should_display_compatibility_notices() ) {
?>
composer install',
'' . esc_html( str_replace( ABSPATH, '', __DIR__ ) ) . '
'
);
?>
registered[ $handle ], $wp_scripts->registered[ $handle ]->src ) ) {
return $translations;
}
$handle_filename = basename( $wp_scripts->registered[ $handle ]->src );
$locale = determine_locale();
$lang_dir = WP_LANG_DIR . '/plugins';
// Translations are always based on the unminified filename.
if ( substr( $handle_filename, -7 ) === '.min.js' ) {
$handle_filename = substr( $handle_filename, 0, -7 ) . '.js';
}
// WordPress 5.0 uses md5 hashes of file paths to associate translation
// JSON files with the file they should be included for. This is an md5
// of 'packages/woocommerce-blocks/build/FILENAME.js'.
$core_path_md5 = md5( 'packages/woocommerce-blocks/build/' . $handle_filename );
$core_json_file = $lang_dir . '/woocommerce-' . $locale . '-' . $core_path_md5 . '.json';
$json_translations = is_file( $core_json_file ) && is_readable( $core_json_file ) ? file_get_contents( $core_json_file ) : false; // phpcs:ignore
if ( ! $json_translations ) {
return $translations;
}
// Rather than short circuit pre_load_script_translations, we will output
// core translations using an inline script. This will allow us to continue
// to load feature-plugin translations which may exist as well.
$output = <<\n%s\n\n", $output ); // phpcs:ignore
// Finally, short circuit the pre_load_script_translations hook by returning
// the translation JSON from the feature plugin, if it exists so this hook
// does not run again for the current handle.
$path_md5 = md5( 'build/' . $handle_filename );
$json_file = $lang_dir . '/' . $domain . '-' . $locale . '-' . $path_md5 . '.json';
$translations = is_file( $json_file ) && is_readable( $json_file ) ? file_get_contents( $json_file ) : false; // phpcs:ignore
if ( $translations ) {
return $translations;
}
// Return valid empty Jed locale.
return '{ "locale_data": { "messages": { "": {} } } }';
}
add_filter( 'pre_load_script_translations', 'woocommerce_blocks_get_i18n_data_json', 10, 4 );
/**
* Filter translations so we can retrieve translations from Core when the original and the translated
* texts are the same (which happens when translations are missing).
*
* @param string $translation Translated text based on WC Blocks translations.
* @param string $text Text to translate.
* @param string $domain The text domain.
* @return string WC Blocks translation. In case it's the same as $text, Core translation.
*/
function woocommerce_blocks_get_php_translation_from_core( $translation, $text, $domain ) {
if ( 'woo-gutenberg-products-block' !== $domain ) {
return $translation;
}
// When translation is the same, that could mean the string is not translated.
// In that case, load it from core.
if ( $translation === $text ) {
return translate( $text, 'woocommerce' ); // phpcs:ignore WordPress.WP.I18n.LowLevelTranslationFunction, WordPress.WP.I18n.NonSingularStringLiteralText, WordPress.WP.I18n.TextDomainMismatch
}
return $translation;
}
add_filter( 'gettext', 'woocommerce_blocks_get_php_translation_from_core', 10, 3 );