wp_download_language_pack

Download a language pack.

Description

(string|bool) wp_download_language_pack( (string) $download ); 

Returns (string|bool)

Returns the language code if successfully downloaded (or already installed), or false on failure.

Parameters (1)

0. $download (string)
Language code to download.

Usage

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

Defined (1)

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

/wp-admin/includes/translation-install.php  
  1. function wp_download_language_pack( $download ) { 
  2. // Check if the translation is already installed. 
  3. if ( in_array( $download, get_available_languages() ) ) { 
  4. return $download; 
  5.  
  6. if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) { 
  7. return false; 
  8.  
  9. // Confirm the translation is one we can download. 
  10. $translations = wp_get_available_translations(); 
  11. if ( ! $translations ) { 
  12. return false; 
  13. foreach ( $translations as $translation ) { 
  14. if ( $translation['language'] === $download ) { 
  15. $translation_to_load = true; 
  16. break; 
  17.  
  18. if ( empty( $translation_to_load ) ) { 
  19. return false; 
  20. $translation = (object) $translation; 
  21.  
  22. require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; 
  23. $skin = new Automatic_Upgrader_Skin; 
  24. $upgrader = new Language_Pack_Upgrader( $skin ); 
  25. $translation->type = 'core'; 
  26. $result = $upgrader->upgrade( $translation, array( 'clear_update_cache' => false ) ); 
  27.  
  28. if ( ! $result || is_wp_error( $result ) ) { 
  29. return false; 
  30.  
  31. return $translation->language;