wp_get_installed_translations

Get installed translations.

Description

(array) wp_get_installed_translations( (string) $type ); 

Looks in the wp-content/languages directory for translations of plugins or themes.

Returns (array)

Array of language data.

Parameters (1)

0. $type (string)
What to search for. Accepts plugins,, themes., core.

Usage

  1. if ( !function_exists( 'wp_get_installed_translations' ) ) { 
  2. require_once ABSPATH . WPINC . '/l10n.php'; 
  3.  
  4. // What to search for. Accepts 'plugins', 'themes', 'core'. 
  5. $type = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_get_installed_translations($type); 
  9.  

Defined (1)

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

/wp-includes/l10n.php  
  1. function wp_get_installed_translations( $type ) { 
  2. if ( $type !== 'themes' && $type !== 'plugins' && $type !== 'core' ) 
  3. return array(); 
  4.  
  5. $dir = 'core' === $type ? '' : "/$type"; 
  6.  
  7. if ( ! is_dir( WP_LANG_DIR ) ) 
  8. return array(); 
  9.  
  10. if ( $dir && ! is_dir( WP_LANG_DIR . $dir ) ) 
  11. return array(); 
  12.  
  13. $files = scandir( WP_LANG_DIR . $dir ); 
  14. if ( ! $files ) 
  15. return array(); 
  16.  
  17. $language_data = array(); 
  18.  
  19. foreach ( $files as $file ) { 
  20. if ( '.' === $file[0] || is_dir( WP_LANG_DIR . "$dir/$file" ) ) { 
  21. continue; 
  22. if ( substr( $file, -3 ) !== '.po' ) { 
  23. continue; 
  24. if ( ! preg_match( '/(?:(.+)-)?([a-z]{2, 3}(?:_[A-Z]{2})?(?:_[a-z0-9]+)?).po/', $file, $match ) ) { 
  25. continue; 
  26. if ( ! in_array( substr( $file, 0, -3 ) . '.mo', $files ) ) { 
  27. continue; 
  28.  
  29. list( , $textdomain, $language ) = $match; 
  30. if ( '' === $textdomain ) { 
  31. $textdomain = 'default'; 
  32. $language_data[ $textdomain ][ $language ] = wp_get_pomo_file_data( WP_LANG_DIR . "$dir/$file" ); 
  33. return $language_data;