Language install prompt

This commit is contained in:
Mike Jolley 2015-08-20 16:03:29 +01:00
parent 186257fcd1
commit 0f40e8cdf7
4 changed files with 32 additions and 14 deletions

File diff suppressed because one or more lines are too long

View File

@ -274,10 +274,18 @@ body {
}
}
}
.woocommerce-tracker {
.woocommerce-tracker, .woocommerce-language-pack, .updated {
padding: 24px 24px 0;
margin: 0 0 24px 0;
overflow: hidden;
background: #f5f5f5;
p {
padding: 0;
margin: 0 0 12px;
}
p:last-child {
margin: 0 0 24px 0;
}
}
}
.wc-setup-steps {
@ -351,4 +359,4 @@ body {
margin: 1.18em 0;
display: block;
text-align: center;
}
}

View File

@ -132,7 +132,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 ] );
return esc_url( add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) + 1 ], remove_query_arg( 'translation_updated' ) ) );
}
/**
@ -201,10 +201,20 @@ 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>Its completely optional and shouldnt take longer than five minutes.</strong>', 'woocommerce' ); ?></p>

View File

@ -22,7 +22,7 @@ class WC_Language_Pack_Upgrader {
*
* @var string
*/
protected $repo = 'https://github.com/woothemes/woocommerce-language-packs/raw/v';
protected static $repo = 'https://github.com/woothemes/woocommerce-language-packs/raw/v';
/**
* Initialize the language pack upgrader
@ -40,11 +40,11 @@ class WC_Language_Pack_Upgrader {
*
* @return string
*/
public function get_language_package_uri( $locale = null ) {
public static function get_language_package_uri( $locale = null ) {
if ( is_null( $locale ) ) {
$locale = get_locale();
}
return $this->repo . WC_VERSION . '/packages/' . $locale . '.zip';
return self::$repo . WC_VERSION . '/packages/' . $locale . '.zip';
}
/**
@ -87,7 +87,7 @@ class WC_Language_Pack_Upgrader {
*
* @return bool
*/
public function has_available_update( $locale = null ) {
public static function has_available_update( $locale = null ) {
if ( is_null( $locale ) ) {
$locale = get_locale();
}
@ -99,8 +99,8 @@ class WC_Language_Pack_Upgrader {
$version = get_option( 'woocommerce_language_pack_version', array( '0', $locale ) );
if ( ! is_array( $version ) || version_compare( $version[0], WC_VERSION, '<' ) || $version[1] !== $locale ) {
if ( $this->check_if_language_pack_exists( $locale ) ) {
$this->configure_woocommerce_upgrade_notice();
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
@ -114,7 +114,7 @@ class WC_Language_Pack_Upgrader {
/**
* Configure the WooCommerce translation upgrade notice
*/
public function configure_woocommerce_upgrade_notice() {
public static function configure_woocommerce_upgrade_notice() {
WC_Admin_Notices::add_notice( 'translation_upgrade' );
}
@ -123,8 +123,8 @@ class WC_Language_Pack_Upgrader {
*
* @return bool
*/
public function check_if_language_pack_exists( $locale ) {
$response = wp_safe_remote_get( $this->get_language_package_uri( $locale ), array( 'timeout' => 60 ) );
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;