返回介绍

wp_download_language_pack()

发布于 2017-09-11 11:54:09 字数 2247 浏览 991 评论 0 收藏 0

wp_download_language_pack( string $download )

Download a language pack.


description


参数

$download

(string) (Required) Language code to download.


返回值

(string|bool) Returns the language code if successfully downloaded (or already installed), or false on failure.


源代码

File: wp-admin/includes/translation-install.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;
}

更新日志

Versiondescription
4.0.0Introduced.

相关函数

Uses

  • wp-includes/load.php: wp_is_file_mod_allowed()
  • wp-admin/includes/translation-install.php: wp_get_available_translations()
  • wp-includes/l10n.php: get_available_languages()
  • wp-includes/load.php: is_wp_error()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文