On this page
wp_get_available_translations(): array[]
Get available translations from the WordPress.org API.
Description
See also
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.
Source
File: wp-admin/includes/translation-install.php. View all references
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;
}
Related
Uses
| Uses | Description |
|---|---|
| wp_installing() wp-includes/load.php | Check or set whether WordPress is in “installation” mode. |
| translations_api() wp-admin/includes/translation-install.php | Retrieve translations from WordPress Translation API. |
| set_site_transient() wp-includes/option.php | Sets/updates the value of a site transient. |
| get_site_transient() wp-includes/option.php | Retrieves the value of a site transient. |
| is_wp_error() wp-includes/load.php | Checks whether the given variable is a WordPress Error. |
Used By
| Used By | Description |
|---|---|
| wp_dropdown_languages() wp-includes/l10n.php | Displays or returns a Language selector. |
| wp_download_language_pack() wp-admin/includes/translation-install.php | Download a language pack. |
Changelog
| Version | Description |
|---|---|
| 4.0.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_get_available_translations