Get available translations from the WordPress.org API.
Description
See also
Return
array Array of translations keyed by the language code, each an associative array of data.If the API response results in an error, an empty array will be returned.
...$0
arraylanguage
stringLanguage code.version
stringWordPress version.updated
stringDate the translation was last updated, in MySQL datetime format.english_name
stringEnglish name of the language.native_name
stringNative name of the language.package
stringURL to download the translation package.iso
string[]Array of ISO language codes.strings
arrayArray of translated strings used in the installation process.
Source
function wp_get_available_translations() { if ( ! wp_installing() ) { $translations = get_site_transient( 'available_translations' ); if ( false !== $translations ) { return $translations; } } $api = translations_api( 'core', array( 'version' => wp_get_wp_version() ) ); if ( is_wp_error( $api ) || empty( $api['translations'] ) ) { return array(); } $translations = array(); // Key the array with the language code. 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
Show 1 moreShow lessUses Description wp_get_wp_version() wp-includes/functions.php
Returns the current WordPress version.
wp_installing() wp-includes/load.php
Checks or sets 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 Description wp_download_language_pack() wp-admin/includes/translation-install.php
Download a language pack.
Changelog
Version Description 4.0.0 Introduced. User Contributed Notes
You must log in before being able to contribute a note or feedback.
Before calling
wp_get_available_translations
you should includetranslation-install.php
like in the following example:Otherwise you might get this fatal error if that file was not included before:
Fatal error: Call to undefined function wp_get_available_translations()