下载语言包。

原型

wp_download_language_pack( string $download )

参数

$download (string) (Required) 要下载的语言代码。

返回值

(string|bool)  如果成功下载(或已安装),则返回语言代码;如果失败,则返回false。

源文件

路径:wp-admin/includes/translation-install.php

<?php
...
function wp_download_language_pack( $download ) {
	// Check if the translation is already installed.
	if ( in_array( $download, get_available_languages() ) ) {
		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;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/wp_download_language_pack/