locale => result. */ public function install(): array { $settings = ( new Settings() )->all(); if ( empty( $settings['language_packs'] ) || ! apply_filters( 'translateplus_language_packs_enabled', true ) || ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) ) { return array(); } require_once ABSPATH . 'wp-admin/includes/translation-install.php'; if ( ! wp_can_install_language_pack() ) { Logger::info( 'Language packs not installed: the server does not allow direct file writes.' ); return array(); } $available = array_column( (array) wp_get_available_translations(), 'language' ); $results = array(); foreach ( Languages::targets() as $lang ) { $locale = Languages::locale( $lang ); if ( ! in_array( $locale, $available, true ) ) { // Fall back to the first locale sharing the language, e.g. pt -> pt_BR. $prefix = strtolower( strtok( $lang, '-' ) ) . '_'; $match = current( array_filter( $available, static function ( $l ) use ( $prefix ) { return 0 === strpos( strtolower( $l ), $prefix ); } ) ); $locale = $match ?: $locale; } $results[ $locale ] = wp_download_language_pack( $locale ) ? 'core' : 'unavailable'; } // Theme and plugin translations for the now-installed locales. wp_clean_update_cache(); wp_update_plugins(); wp_update_themes(); $updates = wp_get_translation_updates(); if ( $updates ) { require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; $upgrader = new \Language_Pack_Upgrader( new \Automatic_Upgrader_Skin() ); $upgrader->bulk_upgrade( $updates ); } Logger::info( sprintf( 'WordPress language packs: %s; %d theme/plugin translation packages installed.', implode( ', ', array_map( static function ( $l, $r ) { return "$l ($r)"; }, array_keys( $results ), $results ) ), count( $updates ) ) ); if ( class_exists( '\TranslatePlus\Strings\Strings' ) ) { \TranslatePlus\Strings\Strings::flush_cache(); } return $results; } }