wp_get_available_translations() WordPress Function

The wp_get_available_translations() function is used to get an array of available translation files. These files are used to translate WordPress into different languages.

wp_get_available_translations() #

Get available translations from the WordPress.org API.


Description

Top ↑

See also


Top ↑

Return

(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.


Top ↑

Source

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

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


Top ↑

Changelog

Changelog
VersionDescription
4.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.