wp_get_available_translations()

Get available translations from the WordPress.org API.


Description Description


Return Return

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


Top ↑

Source Source

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

Top ↑

Changelog Changelog

Changelog
Version Description
4.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note content
    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()

You must log in before being able to contribute a note or feedback.