On this page
wp_download_language_pack( string $download ): string|false
Download a language pack.
Description
See also
Parameters
$downloadstring Required-
Language code to download.
Return
string|false Returns the language code if successfully downloaded (or already installed), or false on failure.
Source
File: wp-admin/includes/translation-install.php. View all references
function wp_download_language_pack( $download ) {
// Check if the translation is already installed.
if ( in_array( $download, get_available_languages(), true ) ) {
return $download;
}
if ( ! wp_is_file_mod_allowed( 'download_language_pack' ) ) {
return false;
}
// Confirm the translation is one we can download.
$translations = wp_get_available_translations();
if ( ! $translations ) {
return false;
}
foreach ( $translations as $translation ) {
if ( $translation['language'] === $download ) {
$translation_to_load = true;
break;
}
}
if ( empty( $translation_to_load ) ) {
return false;
}
$translation = (object) $translation;
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
$skin = new Automatic_Upgrader_Skin;
$upgrader = new Language_Pack_Upgrader( $skin );
$translation->type = 'core';
$result = $upgrader->upgrade( $translation, array( 'clear_update_cache' => false ) );
if ( ! $result || is_wp_error( $result ) ) {
return false;
}
return $translation->language;
}
Related
Uses
| Uses | Description |
|---|---|
| wp_is_file_mod_allowed() wp-includes/load.php | Determines whether file modifications are allowed. |
| wp_get_available_translations() wp-admin/includes/translation-install.php | Get available translations from the WordPress.org API. |
| get_available_languages() wp-includes/l10n.php | Gets all available languages based on the presence of *.mo files in a given directory. |
| is_wp_error() wp-includes/load.php | Checks whether the given variable is a WordPress Error. |
Changelog
| Version | Description |
|---|---|
| 4.0.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_download_language_pack