locale = $this->get_admin_locale(); if ( $this->is_default_language( $this->locale ) ) { return; } $this->init( $args ); if ( $show_translation_box ) { add_action( $this->hook, array( $this, 'promo' ) ); } } /** * Returns whether the language is en_US. * * @param string $language The language to check. * * @return bool Returns true if the language is en_US. */ protected function is_default_language( $language ) { return 'en_US' === $language; } /** * Returns the locale used in the admin. * * WordPress 4.7 introduced the ability for users to specify an Admin language * different from the language used on the front end. This checks if the feature * is available and returns the user's language, with a fallback to the site's language. * Can be removed when support for WordPress 4.6 will be dropped, in favor * of WordPress get_user_locale() that already fallbacks to the site’s locale. * * @returns string The locale. */ private function get_admin_locale() { if ( function_exists( 'get_user_locale' ) ) { return get_user_locale(); } return get_locale(); } /** * This is where you decide where to display the messages and where you set the plugin specific variables. * * @access private * * @param array $args */ private function init( $args ) { foreach ( $args as $key => $arg ) { $this->$key = $arg; } } /** * Check whether the promo should be hidden or not * * @access private * * @return bool */ private function hide_promo() { $hide_promo = get_transient( 'yoast_i18n_' . $this->project_slug . '_promo_hide' ); if ( ! $hide_promo ) { if ( filter_input( INPUT_GET, 'remove_i18n_promo', FILTER_VALIDATE_INT ) === 1 ) { // No expiration time, so this would normally not expire, but it wouldn't be copied to other sites etc. set_transient( 'yoast_i18n_' . $this->project_slug . '_promo_hide', true ); $hide_promo = true; } } return $hide_promo; } /** * Returns the i18n_promo message from the i18n_module. Returns en empty string if the promo shouldn't be shown. * * @access public * * @return string The i18n promo message. */ public function get_promo_message() { if ( ! $this->is_default_language( $this->locale ) && ! $this->hide_promo() ) { return $this->promo_message(); } return ''; } /** * Generates a promo message * * @access private * * @return bool|string $message */ private function promo_message() { $this->translation_details(); $message = false; if ( $this->translation_exists && $this->translation_loaded && $this->percent_translated < 90 ) { $message = __( 'As you can see, there is a translation of this plugin in %1$s. This translation is currently %3$d%% complete. We need your help to make it complete and to fix any errors. Please register at %4$s to help complete the translation to %1$s!', $this->textdomain ); } else if ( ! $this->translation_loaded && $this->translation_exists ) { $message = __( 'You\'re using WordPress in %1$s. While %2$s has been translated to %1$s for %3$d%%, it\'s not been shipped with the plugin yet. You can help! Register at %4$s to help complete the translation to %1$s!', $this->textdomain ); } else if ( ! $this->translation_exists ) { $message = __( 'You\'re using WordPress in a language we don\'t support yet. We\'d love for %2$s to be translated in that language too, but unfortunately, it isn\'t right now. You can change that! Register at %4$s to help translate it!', $this->textdomain ); } $registration_link = sprintf( '%2$s', esc_url( $this->register_url ), esc_html( $this->glotpress_name ) ); $message = sprintf( $message, esc_html( $this->locale_name ), esc_html( $this->plugin_name ), $this->percent_translated, $registration_link ); if ( $message ) { $message = '
' . $message . '
' . '' . __( 'Register now »', $this->textdomain ) . '
'; } return $message; } /** * Returns a button that can be used to dismiss the i18n-message. * * @access private * * @return string */ public function get_dismiss_i18n_message_button() { return sprintf( /* translators: %1$s is the notification dismissal link start tag, %2$s is the link closing tag. */ __( '%1$sPlease don\'t show me this notification anymore%2$s', $this->textdomain ), '', '' ); } /** * Outputs a promo box. * * @access public */ public function promo() { $message = $this->get_promo_message(); if ( $message ) { echo '