Removed our own language packs manager
This commit is contained in:
parent
d2d1330898
commit
c53fe24c20
|
@ -274,7 +274,7 @@ body {
|
|||
}
|
||||
}
|
||||
}
|
||||
.woocommerce-tracker, .woocommerce-language-pack, .updated {
|
||||
.woocommerce-tracker, .updated {
|
||||
padding: 24px 24px 0;
|
||||
margin: 0 0 24px 0;
|
||||
overflow: hidden;
|
||||
|
|
|
@ -22,11 +22,10 @@ class WC_Admin_Notices {
|
|||
* @var array
|
||||
*/
|
||||
private $core_notices = array(
|
||||
'install' => 'install_notice',
|
||||
'update' => 'update_notice',
|
||||
'template_files' => 'template_file_check_notice',
|
||||
'theme_support' => 'theme_check_notice',
|
||||
'translation_upgrade' => 'translation_upgrade_notice'
|
||||
'install' => 'install_notice',
|
||||
'update' => 'update_notice',
|
||||
'template_files' => 'template_file_check_notice',
|
||||
'theme_support' => 'theme_check_notice'
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -36,7 +35,6 @@ class WC_Admin_Notices {
|
|||
add_action( 'switch_theme', array( $this, 'reset_admin_notices' ) );
|
||||
add_action( 'woocommerce_installed', array( $this, 'reset_admin_notices' ) );
|
||||
add_action( 'wp_loaded', array( $this, 'hide_notices' ) );
|
||||
add_action( 'woocommerce_hide_translation_upgrade_notice', array( $this, 'hide_translation_upgrade_notice' ) );
|
||||
|
||||
if ( current_user_can( 'manage_woocommerce' ) ) {
|
||||
add_action( 'admin_print_styles', array( $this, 'add_notices' ) );
|
||||
|
@ -106,13 +104,6 @@ class WC_Admin_Notices {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide translation upgrade message
|
||||
*/
|
||||
public function hide_translation_upgrade_notice() {
|
||||
update_option( 'woocommerce_language_pack_version', array( WC_VERSION, get_locale() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add notices + styles if needed.
|
||||
*/
|
||||
|
@ -154,22 +145,6 @@ class WC_Admin_Notices {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the translation upgrade notice
|
||||
*/
|
||||
public function translation_upgrade_notice() {
|
||||
$screen = get_current_screen();
|
||||
$locale = get_locale();
|
||||
|
||||
if ( 'en_US' === $locale ) {
|
||||
self::hide_translation_upgrade_notice();
|
||||
}
|
||||
|
||||
if ( 'update-core' !== $screen->id && 'en_US' !== $locale ) {
|
||||
include( 'views/html-notice-translation-upgrade.php' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a notice highlighting bad template files
|
||||
*/
|
||||
|
|
|
@ -131,7 +131,7 @@ class WC_Admin_Setup_Wizard {
|
|||
|
||||
public function get_next_step_link() {
|
||||
$keys = array_keys( $this->steps );
|
||||
return add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) + 1 ], remove_query_arg( 'translation_updated' ) );
|
||||
return add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) + 1 ] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -201,20 +201,6 @@ class WC_Admin_Setup_Wizard {
|
|||
* Introduction step
|
||||
*/
|
||||
public function wc_setup_introduction() {
|
||||
$locale = get_locale();
|
||||
|
||||
if ( isset( $_GET['translation_updated'] ) ) {
|
||||
WC_Language_Pack_Upgrader::language_update_messages();
|
||||
} elseif( 'en_US' !== $locale && WC_Language_Pack_Upgrader::has_available_update( $locale ) ) {
|
||||
?>
|
||||
<div class="woocommerce-message woocommerce-language-pack">
|
||||
<p><?php printf( esc_html__( 'WooCommerce is available in %s. Would you like to use this translation?', 'woocommerce' ), $locale ); ?></p>
|
||||
<p class="submit">
|
||||
<a href="<?php echo esc_url( wp_nonce_url( admin_url( 'index.php?page=wc-setup&action=translation_upgrade' ), 'setup_language' ) ); ?>" class="button-primary"><?php _e( 'Install Translation', 'woocommerce' ); ?></a>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<h1><?php _e( 'Welcome to the world of WooCommerce!', 'woocommerce' ); ?></h1>
|
||||
<p><?php _e( 'Thank you for choosing WooCommerce to power your online store! This quick setup wizard will help you configure the basic settings. <strong>It’s completely optional and shouldn’t take longer than five minutes.</strong>', 'woocommerce' ); ?></p>
|
||||
|
|
|
@ -141,11 +141,6 @@ class WC_Admin_Status {
|
|||
}
|
||||
}
|
||||
|
||||
// Manual translation update messages
|
||||
if ( isset( $_GET['translation_updated'] ) ) {
|
||||
WC_Language_Pack_Upgrader::language_update_messages();
|
||||
}
|
||||
|
||||
// Display message if settings settings have been saved
|
||||
if ( isset( $_REQUEST['settings-updated'] ) ) {
|
||||
echo '<div class="updated"><p>' . __( 'Your changes have been saved.', 'woocommerce' ) . '</p></div>';
|
||||
|
@ -202,14 +197,6 @@ class WC_Admin_Status {
|
|||
)
|
||||
);
|
||||
|
||||
if ( get_locale() !== 'en_US' ) {
|
||||
$tools['translation_upgrade'] = array(
|
||||
'name' => __( 'Translation Upgrade', 'woocommerce' ),
|
||||
'button' => __( 'Force Translation Upgrade', 'woocommerce' ),
|
||||
'desc' => __( '<strong class="red">Note:</strong> This option will force the translation upgrade for your language if a translation is available.', 'woocommerce' ),
|
||||
);
|
||||
}
|
||||
|
||||
return apply_filters( 'woocommerce_debug_tools', $tools );
|
||||
}
|
||||
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Admin View: Notice - Translation Upgrade
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
?>
|
||||
<div id="message" class="updated woocommerce-message wc-connect">
|
||||
<p><?php printf( __( '<strong>WooCommerce Translation Available</strong> – Install or update your <code>%s</code> translation to version <code>%s</code>.', 'woocommerce' ), get_locale(), WC_VERSION ); ?></p>
|
||||
|
||||
<p>
|
||||
<?php if ( is_multisite() ) : ?>
|
||||
<a href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin.php?page=wc-status&tab=tools&action=translation_upgrade' ), 'debug_action' ) ); ?>" class="button-primary"><?php _e( 'Update Translation', 'woocommerce' ); ?></a>
|
||||
<?php else : ?>
|
||||
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'do-translation-upgrade' ), admin_url( 'update-core.php' ) ), 'upgrade-translations' ) ); ?>" class="button-primary"><?php _e( 'Update Translation', 'woocommerce' ); ?></a>
|
||||
<a href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin.php?page=wc-status&tab=tools&action=translation_upgrade' ), 'debug_action' ) ); ?>" class="button-secondary"><?php _e( 'Force Update Translation', 'woocommerce' ); ?></a>
|
||||
<?php endif; ?>
|
||||
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wc-hide-notice', 'translation_upgrade' ), 'woocommerce_hide_notices_nonce', '_wc_notice_nonce' ) ); ?>" class="button-secondary skip"><?php _e( 'Hide This Message', 'woocommerce' ); ?></a>
|
||||
</p>
|
||||
</div>
|
|
@ -1,273 +0,0 @@
|
|||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
}
|
||||
|
||||
/**
|
||||
* WooCommerce Language Pack Upgrader class
|
||||
*
|
||||
* Downloads the last language pack.
|
||||
*
|
||||
* @class WC_Language_Pack_Upgrader
|
||||
* @version 2.4.0
|
||||
* @package WooCommerce/Classes/Language
|
||||
* @category Class
|
||||
* @author WooThemes
|
||||
*/
|
||||
class WC_Language_Pack_Upgrader {
|
||||
|
||||
/**
|
||||
* Languages repository
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $repo = 'https://github.com/woothemes/woocommerce-language-packs/raw/v';
|
||||
|
||||
/**
|
||||
* Initialize the language pack upgrader
|
||||
*/
|
||||
public function __construct() {
|
||||
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_for_update' ) );
|
||||
add_filter( 'upgrader_pre_download', array( $this, 'version_update' ), 10, 2 );
|
||||
add_action( 'woocommerce_installed', array( __CLASS__, 'has_available_update' ) );
|
||||
add_action( 'update_option_WPLANG', array( $this, 'updated_language_option' ), 10, 2 );
|
||||
add_filter( 'admin_init', array( $this, 'manual_language_update' ), 10 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language package URI.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_language_package_uri( $locale = null ) {
|
||||
if ( is_null( $locale ) ) {
|
||||
$locale = get_locale();
|
||||
}
|
||||
return self::$repo . WC_VERSION . '/packages/' . $locale . '.zip';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for language updates
|
||||
*
|
||||
* @param object $data Transient update data
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function check_for_update( $data ) {
|
||||
if ( self::has_available_update() ) {
|
||||
$locale = get_locale();
|
||||
|
||||
$data->translations[] = array(
|
||||
'type' => 'plugin',
|
||||
'slug' => 'woocommerce',
|
||||
'language' => $locale,
|
||||
'version' => WC_VERSION,
|
||||
'updated' => date( 'Y-m-d H:i:s' ),
|
||||
'package' => self::get_language_package_uri( $locale ),
|
||||
'autoupdate' => 1
|
||||
);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggered when WPLANG is changed
|
||||
*
|
||||
* @param string $old
|
||||
* @param string $new
|
||||
*/
|
||||
public function updated_language_option( $old, $new ) {
|
||||
self::has_available_update( $new );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if has available translation update
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function has_available_update( $locale = null ) {
|
||||
if ( is_null( $locale ) ) {
|
||||
$locale = get_locale();
|
||||
}
|
||||
|
||||
if ( 'en_US' === $locale ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$version = get_option( 'woocommerce_language_pack_version', array( '0', $locale ) );
|
||||
|
||||
if ( ! is_array( $version ) || version_compare( $version[0], WC_VERSION, '<' ) || $version[1] !== $locale ) {
|
||||
if ( self::check_if_language_pack_exists( $locale ) ) {
|
||||
self::configure_woocommerce_upgrade_notice();
|
||||
return true;
|
||||
} else {
|
||||
// Updated the woocommerce_language_pack_version to avoid searching translations for this release again
|
||||
update_option( 'woocommerce_language_pack_version', array( WC_VERSION, $locale ) );
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the WooCommerce translation upgrade notice
|
||||
*/
|
||||
public static function configure_woocommerce_upgrade_notice() {
|
||||
WC_Admin_Notices::add_notice( 'translation_upgrade' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if language pack exists
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function check_if_language_pack_exists( $locale ) {
|
||||
$response = wp_safe_remote_get( self::get_language_package_uri( $locale ), array( 'timeout' => 60 ) );
|
||||
|
||||
if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the language version in database
|
||||
*
|
||||
* This updates the database while the download the translation package and ensures that not generate download loop
|
||||
* If the installation fails you can redo it in: WooCommerce > Sistem Status > Tools > Force Translation Upgrade
|
||||
*
|
||||
* @param bool $reply Whether to bail without returning the package (default: false)
|
||||
* @param string $package Package URL
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function version_update( $reply, $package ) {
|
||||
if ( $package === self::get_language_package_uri() ) {
|
||||
$this->save_language_version();
|
||||
}
|
||||
|
||||
return $reply;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save language version
|
||||
*/
|
||||
protected function save_language_version() {
|
||||
// Update the language pack version
|
||||
update_option( 'woocommerce_language_pack_version', array( WC_VERSION, get_locale() ) );
|
||||
|
||||
// Remove the translation upgrade notice
|
||||
$notices = get_option( 'woocommerce_admin_notices', array() );
|
||||
$notices = array_diff( $notices, array( 'translation_upgrade' ) );
|
||||
update_option( 'woocommerce_admin_notices', $notices );
|
||||
}
|
||||
|
||||
/**
|
||||
* Manual language update
|
||||
*/
|
||||
public function manual_language_update() {
|
||||
if (
|
||||
is_admin()
|
||||
&& current_user_can( 'update_plugins' )
|
||||
&& isset( $_GET['page'] )
|
||||
&& in_array( $_GET['page'], array( 'wc-status', 'wc-setup' ) )
|
||||
&& isset( $_GET['action'] )
|
||||
&& 'translation_upgrade' == $_GET['action']
|
||||
) {
|
||||
$page = 'wc-status&tab=tools';
|
||||
$wpnonce = 'debug_action';
|
||||
if ( 'wc-setup' == $_GET['page'] ) {
|
||||
$page = 'wc-setup';
|
||||
$wpnonce = 'setup_language';
|
||||
}
|
||||
|
||||
$url = wp_nonce_url( admin_url( 'admin.php?page=' . $page . '&action=translation_upgrade' ), 'language_update' );
|
||||
$tools_url = admin_url( 'admin.php?page=' . $page );
|
||||
|
||||
if ( ! isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'], $wpnonce ) ) {
|
||||
wp_redirect( add_query_arg( array( 'translation_updated' => 2 ), $tools_url ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( false === ( $creds = request_filesystem_credentials( $url, '', false, false, null ) ) ) {
|
||||
wp_redirect( add_query_arg( array( 'translation_updated' => 3 ), $tools_url ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! WP_Filesystem( $creds ) ) {
|
||||
request_filesystem_credentials( $url, '', true, false, null );
|
||||
|
||||
wp_redirect( add_query_arg( array( 'translation_updated' => 3 ), $tools_url ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
// Download the language pack
|
||||
$response = wp_safe_remote_get( self::get_language_package_uri(), array( 'timeout' => 60 ) );
|
||||
if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
|
||||
global $wp_filesystem;
|
||||
|
||||
$upload_dir = wp_upload_dir();
|
||||
$file = trailingslashit( $upload_dir['path'] ) . get_locale() . '.zip';
|
||||
|
||||
// Save the zip file
|
||||
if ( ! $wp_filesystem->put_contents( $file, $response['body'], FS_CHMOD_FILE ) ) {
|
||||
wp_redirect( add_query_arg( array( 'translation_updated' => 3 ), $tools_url ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
// Unzip the file to wp-content/languages/plugins directory
|
||||
$dir = trailingslashit( WP_LANG_DIR ) . 'plugins/';
|
||||
$unzip = unzip_file( $file, $dir );
|
||||
if ( true !== $unzip ) {
|
||||
wp_redirect( add_query_arg( array( 'translation_updated' => 3 ), $tools_url ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
// Delete the package file
|
||||
$wp_filesystem->delete( $file );
|
||||
|
||||
// Update the language pack version
|
||||
$this->save_language_version();
|
||||
|
||||
// Redirect and show a success message
|
||||
wp_redirect( add_query_arg( array( 'translation_updated' => 1 ), $tools_url ) );
|
||||
exit;
|
||||
} else {
|
||||
// Don't have a valid package for the current language!
|
||||
wp_redirect( add_query_arg( array( 'translation_updated' => 4 ), $tools_url ) );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Language update messages
|
||||
*
|
||||
* @since 2.4.5
|
||||
*/
|
||||
public static function language_update_messages() {
|
||||
switch ( $_GET['translation_updated'] ) {
|
||||
case 2 :
|
||||
echo '<div class="error"><p>' . __( 'Failed to install/update the translation:', 'woocommerce' ) . ' ' . __( 'Seems you don\'t have permission to do this!', 'woocommerce' ) . '</p></div>';
|
||||
break;
|
||||
case 3 :
|
||||
echo '<div class="error"><p>' . __( 'Failed to install/update the translation:', 'woocommerce' ) . ' ' . sprintf( __( 'An authentication error occurred while updating the translation. Please try again or configure your %sUpgrade Constants%s.', 'woocommerce' ), '<a href="http://codex.wordpress.org/Editing_wp-config.php#WordPress_Upgrade_Constants">', '</a>' ) . '</p></div>';
|
||||
break;
|
||||
case 4 :
|
||||
echo '<div class="error"><p>' . __( 'Failed to install/update the translation:', 'woocommerce' ) . ' ' . __( 'Sorry but there is no translation available for your language =/', 'woocommerce' ) . '</p></div>';
|
||||
break;
|
||||
|
||||
default :
|
||||
// Force WordPress find for new updates and hide the WooCommerce translation update
|
||||
set_site_transient( 'update_plugins', null );
|
||||
|
||||
echo '<div class="updated"><p>' . __( 'Translations installed/updated successfully!', 'woocommerce' ) . '</p></div>';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new WC_Language_Pack_Upgrader();
|
|
@ -242,7 +242,6 @@ final class WooCommerce {
|
|||
include_once( 'includes/class-wc-countries.php' ); // Defines countries and states
|
||||
include_once( 'includes/class-wc-integrations.php' ); // Loads integrations
|
||||
include_once( 'includes/class-wc-cache-helper.php' ); // Cache Helper
|
||||
include_once( 'includes/class-wc-language-pack-upgrader.php' ); // Download/update languages
|
||||
|
||||
if ( defined( 'WP_CLI' ) && WP_CLI ) {
|
||||
include_once( 'includes/class-wc-cli.php' );
|
||||
|
@ -312,25 +311,15 @@ final class WooCommerce {
|
|||
*
|
||||
* Note: the first-loaded translation file overrides any following ones if the same translation is present.
|
||||
*
|
||||
* Admin Locales are found in:
|
||||
* - WP_LANG_DIR/woocommerce/woocommerce-admin-LOCALE.mo
|
||||
* - WP_LANG_DIR/plugins/woocommerce-admin-LOCALE.mo
|
||||
*
|
||||
* Frontend/global Locales found in:
|
||||
* - WP_LANG_DIR/woocommerce/woocommerce-LOCALE.mo
|
||||
* - woocommerce/i18n/languages/woocommerce-LOCALE.mo (which if not found falls back to:)
|
||||
* - WP_LANG_DIR/plugins/woocommerce-LOCALE.mo
|
||||
* Locales found in:
|
||||
* - WP_LANG_DIR/woocommerce/woocommerce-LOCALE.mo
|
||||
* - WP_LANG_DIR/plugins/woocommerce-LOCALE.mo
|
||||
*/
|
||||
public function load_plugin_textdomain() {
|
||||
$locale = apply_filters( 'plugin_locale', get_locale(), 'woocommerce' );
|
||||
|
||||
if ( $this->is_request( 'admin' ) ) {
|
||||
load_textdomain( 'woocommerce', WP_LANG_DIR . '/woocommerce/woocommerce-admin-' . $locale . '.mo' );
|
||||
load_textdomain( 'woocommerce', WP_LANG_DIR . '/plugins/woocommerce-admin-' . $locale . '.mo' );
|
||||
}
|
||||
|
||||
load_textdomain( 'woocommerce', WP_LANG_DIR . '/woocommerce/woocommerce-' . $locale . '.mo' );
|
||||
load_plugin_textdomain( 'woocommerce', false, plugin_basename( dirname( __FILE__ ) ) . "/i18n/languages" );
|
||||
load_plugin_textdomain( 'woocommerce', false, plugin_basename( dirname( __FILE__ ) ) . '/i18n/languages' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue