get_available_languages

Get all available languages based on the presence of *.mo files in a given directory.

Description

(array) get_available_languages( (null) $dir = null ); 

The default directory is WP_LANG_DIR.

Returns (array)

An array of language codes or an empty array if no languages are present. Language codes are formed by stripping the .mo extension from the language file names.

Parameters (1)

0. $dir — Optional. (null) => null
A directory to search for language files. Default WP_LANG_DIR.

Usage

  1. if ( !function_exists( 'get_available_languages' ) ) { 
  2. require_once ABSPATH . WPINC . '/l10n.php'; 
  3.  
  4. // A directory to search for language files. 
  5. // Default WP_LANG_DIR. 
  6. $dir = null; 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = get_available_languages($dir); 
  10.  

Defined (1)

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

/wp-includes/l10n.php  
  1. function get_available_languages( $dir = null ) { 
  2. $languages = array(); 
  3.  
  4. $lang_files = glob( ( is_null( $dir ) ? WP_LANG_DIR : $dir ) . '/*.mo' ); 
  5. if ( $lang_files ) { 
  6. foreach ( $lang_files as $lang_file ) { 
  7. $lang_file = basename( $lang_file, '.mo' ); 
  8. if ( 0 !== strpos( $lang_file, 'continents-cities' ) && 0 !== strpos( $lang_file, 'ms-' ) && 
  9. 0 !== strpos( $lang_file, 'admin-' ) ) { 
  10. $languages[] = $lang_file; 
  11.   
  12. /** 
  13. * Filters the list of available language codes. 
  14. * @since 4.7.0 
  15. * @param array $languages An array of available language codes. 
  16. * @param string $dir The directory where the language files were found. 
  17. */ 
  18. return apply_filters( 'get_available_languages', $languages, $dir );