返回介绍

wp_get_available_translations()

发布于 2017-09-11 12:00:49 字数 2892 浏览 1143 评论 0 收藏 0

wp_get_available_translations()

Get available translations from the WordPress.org API.


description


返回值

(array) Array of translations, each an array of data. If the API response results in an error, an empty array will be returned.


源代码

File: wp-admin/includes/translation-install.php

function wp_get_available_translations() {
	if ( ! wp_installing() && false !== ( $translations = get_site_transient( 'available_translations' ) ) ) {
		return $translations;
	}

	include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version

	$api = translations_api( 'core', array( 'version' => $wp_version ) );

	if ( is_wp_error( $api ) || empty( $api['translations'] ) ) {
		return array();
	}

	$translations = array();
	// Key the array with the language code for now.
	foreach ( $api['translations'] as $translation ) {
		$translations[ $translation['language'] ] = $translation;
	}

	if ( ! defined( 'WP_INSTALLING' ) ) {
		set_site_transient( 'available_translations', $translations, 3 * HOUR_IN_SECONDS );
	}

	return $translations;
}

更新日志

Versiondescription
4.0.0Introduced.

相关函数

Uses

  • wp-includes/load.php: wp_installing()
  • wp-admin/includes/translation-install.php: translations_api()
  • wp-includes/option.php: set_site_transient()
  • wp-includes/option.php: get_site_transient()
  • wp-includes/load.php: is_wp_error()

Used By

  • wp-includes/l10n.php: wp_dropdown_languages()
  • wp-admin/includes/translation-install.php: wp_download_language_pack()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 2You must log in to vote on the helpfulness of this note Contributed by Fahad Alduraibi

    Before calling wp_get_available_translations you should include translation-install.php like in the following example:

    
    require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
    $language_list = wp_get_available_translations();
    

    Otherwise you might get this fatal error if that file was not included before:
    Fatal error: Call to undefined function wp_get_available_translations()

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

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

发布评论

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