wp_get_available_translations

函数
wp_get_available_translations ( No parameters )
返回值
  • (array[]) Array of translations, each an array of data, keyed by the language. If the API response results in an error, an empty array will be returned.
相关
  • translations_api()
定义位置
相关方法
wp_get_installed_translationswp_set_script_translationsget_available_languageswp_get_translation_updateswp_get_video_extensions
引入
4.0.0
弃用
-

wp_get_available_translations: 这个函数检索WordPress的可用翻译。它不接受任何参数,并返回一个翻译对象数组,每个对象包含语言代码、版本和翻译状态。

从WordPress.org API获取可用的翻译。

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

	// Include an unmodified $wp_version.
	require ABSPATH . WPINC . '/version.php';

	$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;
}

常见问题

FAQs
查看更多 >