Warning: Array to string conversion in /mnt/data/home/502433.cloudwaysapps.com/rhbymdevka/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 808
Warning: foreach() argument must be of type array|object, string given in /mnt/data/home/502433.cloudwaysapps.com/rhbymdevka/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 813
Warning: Array to string conversion in /mnt/data/home/502433.cloudwaysapps.com/rhbymdevka/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 808
PUM_Utils_Alerts::translation_request( array $alerts = array() )
Description Description
Warning: Array to string conversion in /mnt/data/home/502433.cloudwaysapps.com/rhbymdevka/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 808
Warning: foreach() argument must be of type array|object, string given in /mnt/data/home/502433.cloudwaysapps.com/rhbymdevka/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 813
Warning: Array to string conversion in /mnt/data/home/502433.cloudwaysapps.com/rhbymdevka/public_html/wp-content/themes/wporg-developer/inc/template-tags.php on line 808
Parameters Parameters
- $alerts
-
(Optional)
Default value: array()
Return Return
(array)
Source Source
File: classes/Utils/Alerts.php
public static function translation_request( $alerts = array() ) { $version = explode( '.', Popup_Maker::$VER ); // Get only the major.minor version exclude the point releases. $version = $version[0] . '.' . $version[1]; $code = 'translation_request_' . $version; // Bail Early if they have already dismissed. if ( self::has_dismissed_alert( $code ) ) { return $alerts; } // Get locales based on the HTTP accept language header. $locales_from_header = PUM_Utils_I10n::get_http_locales(); // Abort early if no locales in header. if ( empty( $locales_from_header ) ) { return $alerts; } // Get acceptable non EN WordPress locales based on the HTTP accept language header. // Used when the current locale is EN only I believe. $non_en_locales_from_header = PUM_Utils_I10n::get_non_en_accepted_wp_locales_from_header(); // If no additional languages are supported abort if ( empty( $non_en_locales_from_header ) ) { return $alerts; } /** * Assume all at this point are possible polyglots. * * Viewing in English! * -- Translation available in one additional language! * ---- Show notice that there other language is available and we need help translating. * -- Translation available in more than one language! * ---- Show notice that their other languages are available and need help translating. * -- Translation not available! * ---- Show notice that plugin is not translated and we need help. * Else If translation for their language(s) exists, but isn't up to date! * -- Show notice that their language is available, but out of date and need help translating. * Else If translations for their language doesn't exist! * -- Show notice that plugin is not translated and we need help. */ $current_locale = function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); // Get the active language packs of the plugin. $translation_status = PUM_Utils_I10n::translation_status(); // Retrieve all the WordPress locales in which the plugin is translated. $locales_with_translations = wp_list_pluck( $translation_status, 'language' ); $locale_translation_versions = wp_list_pluck( $translation_status, 'version' ); // Suggests existing langpacks $suggested_locales_with_langpack = array_values( array_intersect( $non_en_locales_from_header, $locales_with_translations ) ); $current_locale_is_suggested = in_array( $current_locale, $suggested_locales_with_langpack ); $current_locale_is_translated = in_array( $current_locale, $locales_with_translations ); // Last chance to abort early before querying all available languages. // We abort here if the user is already using a translated language that is up to date! if ( $current_locale_is_suggested && $current_locale_is_translated && version_compare( $locale_translation_versions[ $current_locale ], Popup_Maker::$VER, '>=' ) ) { return $alerts; } // Retrieve all the WordPress locales. $locales_supported_by_wordpress = PUM_Utils_I10n::available_locales(); // Get the native language names of the locales. $suggest_translated_locale_names = array(); foreach ( $suggested_locales_with_langpack as $locale ) { $suggest_translated_locale_names[ $locale ] = $locales_supported_by_wordpress[ $locale ]['native_name']; } $suggest_string = ''; // If we get this far, they clearly have multiple language available // If current locale is english but they have others available, they are likely polyglots. $currently_in_english = strpos( $current_locale, 'en' ) === 0; // Currently in English. if ( $currently_in_english ) { // Only one locale suggestion. if ( 1 === count( $suggest_translated_locale_names ) ) { $language = current( $suggest_translated_locale_names ); $suggest_string = sprintf( /* translators: %s: native language name. */ __( 'This plugin is also available in %1$s. <a href="%2$s" target="_blank">Help improve the translation!</a>', 'popup-maker' ), $language, esc_url( 'https://translate.wordpress.org/projects/wp-plugins/popup-maker' ) ); // Multiple locale suggestions. } elseif ( ! empty( $suggest_translated_locale_names ) ) { $primary_language = current( $suggest_translated_locale_names ); array_shift( $suggest_translated_locale_names ); $other_suggest = ''; foreach ( $suggest_translated_locale_names as $language ) { $other_suggest .= $language . ', '; } $suggest_string = sprintf( /* translators: 1: native language name, 2: other native language names, comma separated */ __( 'This plugin is also available in %1$s (also: %2$s). <a href="%3$s" target="_blank">Help improve the translation!</a>', 'popup-maker' ), $primary_language, trim( $other_suggest, ' ,' ), esc_url( 'https://translate.wordpress.org/projects/wp-plugins/popup-maker' ) ); // Non-English locale in header, no translations. } elseif ( ! empty( $non_en_locales_from_header ) ) { if ( 1 === count( $non_en_locales_from_header ) ) { $locale = reset( $non_en_locales_from_header ); $suggest_string = sprintf( /* translators: 1: native language name, 2: URL to translate.wordpress.org */ __( 'This plugin is not translated into %1$s yet. <a href="%2$s" target="_blank">Help translate it!</a>', 'popup-maker' ), $locales_supported_by_wordpress[ $locale ]['native_name'], esc_url( 'https://translate.wordpress.org/projects/wp-plugins/popup-maker' ) ); } else { $primary_locale = reset( $non_en_locales_from_header ); $primary_language = $locales_supported_by_wordpress[ $primary_locale ]['native_name']; array_shift( $non_en_locales_from_header ); $other_suggest = ''; foreach ( $non_en_locales_from_header as $locale ) { $other_suggest .= $locales_supported_by_wordpress[ $locale ]['native_name'] . ', '; } $suggest_string = sprintf( /* translators: 1: native language name, 2: other native language names, comma separated */ __( 'This plugin is also available in %1$s (also: %2$s). <a href="%3$s" target="_blank">Help improve the translation!</a>', 'popup-maker' ), $primary_language, trim( $other_suggest, ' ,' ), esc_url( 'https://translate.wordpress.org/projects/wp-plugins/popup-maker' ) ); } } // The plugin has no translation for the current locale. } elseif ( ! $current_locale_is_suggested && ! $current_locale_is_translated ) { $suggest_string = sprintf( __( 'This plugin is not translated into %1$s yet. <a href="%2$s" target="_blank">Help translate it!</a>', 'popup-maker' ), $locales_supported_by_wordpress[ $current_locale ]['native_name'], esc_url( 'https://translate.wordpress.org/projects/wp-plugins/popup-maker' ) ); // The plugin has translations for current locale, but they are out of date. } elseif ( $current_locale_is_suggested && $current_locale_is_translated && version_compare( $locale_translation_versions[ $current_locale ], Popup_Maker::$VER, '<' ) ) { $suggest_string = sprintf( /* translators: %s: native language name. */ __( 'This plugin\'s translation for %1$s is out of date. <a href="%2$s" target="_blank">Help improve the translation!</a>', 'popup-maker' ), $locales_supported_by_wordpress[ $current_locale ]['native_name'], esc_url( 'https://translate.wordpress.org/projects/wp-plugins/popup-maker' ) ); } if ( ! empty( $suggest_string ) ) { $alerts[] = array( 'code' => $code, 'message' => $suggest_string, 'type' => 'info', ); } return $alerts; }
Expand full source code Collapse full source code View on Trac