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

原型

wp_get_available_translations()

返回值

(array)  翻译数组,每个都是数据数组。如果API响应导致错误,则返回空数组。

源文件

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

<?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;
}
...
?>

其他

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