Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Translation info on SIte Health #7439

Open
wants to merge 9 commits into
base: trunk
Choose a base branch
from
76 changes: 76 additions & 0 deletions src/wp-admin/includes/class-wp-debug-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@

$info['wp-plugins-active'] = array(
'label' => __( 'Active Plugins' ),
'show_count' => true,

Check failure on line 204 in src/wp-admin/includes/class-wp-debug-data.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Expected 1 spaces after opening parenthesis; 0 found

Check failure on line 204 in src/wp-admin/includes/class-wp-debug-data.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Expected 1 spaces before closing parenthesis; 0 found
'fields' => array(),
);

Expand All @@ -211,6 +211,11 @@
'fields' => array(),
);

$info['wp-translation'] = array(
'label' => __('Translation'),
'fields' => self::info_translations(),
);

// Conditionally add debug information for multisite setups.
if ( is_multisite() ) {
$site_id = get_current_blog_id();
Expand Down Expand Up @@ -1841,4 +1846,75 @@

return $all_sizes;
}

/**
* Display the list of available translation for Core, plugins and theme.
*
* @return array
* @since 6.8
*
*/
public static function info_translations() {
// Translation updates available.
$translation_updates = wp_get_translation_updates();
$languages = get_available_languages();
$fields = array();
foreach ( $translation_updates as $update ) {
$fields[ $update->type ]['label'] = $update->type;
$available_translations[ 'wp_translations_' . $update->type ][ $update->slug ][] = $update->language;
$is_already_installed = self::is_wp_language_installed( $languages, $update->type, $update->slug );
if ( ! empty( $is_already_installed ) ) {
$translations['updatable'][ $update->type ][ $update->slug ][] = $update->language;
} else {
$translations['missing'][ $update->type ][ $update->slug ][] = $update->language;
}
}

foreach ( $translations as $state => $translation ) {
foreach ( $translation as $type => $elements ) {
foreach ( $elements as $name => $locales ) {
if ( 'missing' === $state ) {
/* translators: the placeholder is a WordPress locale */
$fields[ $type ]['value'][ $name ] = sprintf( __( 'A translation is missing for %s .' ), implode( ', ', $locales ) );
}
if ( 'updatable' === $state ) {
/* translators: the placeholder is a WordPress locale */
$fields[ $type ]['value'][ $name ] = sprintf( __( 'A translation is updatable for %s .' ), implode( ', ', $locales ) );
}
}
}
}

return $fields;
}

/**
* Is the language pack already installed ?
*
* @param array $locales array of WordPress locales.
* @param string $type type of update (may be core, plugin or theme and sometimes core, plugins or themes ).
* @param string $name name of the element (plugin/theme) currently updated. In case of Core update, it's "default"
* @param array|bool $already_installed array of already installed language packs.
*
* @return boolean|array
* @since 6.8
*
*/
public static function is_wp_language_installed( $locales, $type, $name, $already_installed = array() ) {
$installed_translations = wp_get_installed_translations( $type );
if ( ! is_array( $installed_translations ) ) {
return false;
}
foreach ( $locales as $locale ) {
if ( ! empty( $installed_translations[ $name ] ) && $installed_translations[ $name ][ $locale ] ) {
$already_installed[ $type ][ $name ][ $locale ] = $locale;
}
}

if ( ! empty( $already_installed ) ) {
return $already_installed;
}

return false;
}
}
Loading