wp_get_available_translations

Get available translations from the WordPress.org API.

Description

(array) wp_get_available_translations(); 

Returns (array)

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


Usage

  1. if ( !function_exists( 'wp_get_available_translations' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/translation-install.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_get_available_translations(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/translation-install.php  
  1. function wp_get_available_translations() { 
  2. if ( ! wp_installing() && false !== ( $translations = get_site_transient( 'available_translations' ) ) ) { 
  3. return $translations; 
  4.  
  5. include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version 
  6.  
  7. $api = translations_api( 'core', array( 'version' => $wp_version ) ); 
  8.  
  9. if ( is_wp_error( $api ) || empty( $api[translations] ) ) { 
  10. return array(); 
  11.  
  12. $translations = array(); 
  13. // Key the array with the language code for now. 
  14. foreach ( $api[translations] as $translation ) { 
  15. $translations[ $translation['language'] ] = $translation; 
  16.  
  17. if ( ! defined( 'WP_INSTALLING' ) ) { 
  18. set_site_transient( 'available_translations', $translations, 3 * HOUR_IN_SECONDS ); 
  19.  
  20. return $translations;