wppaste
WordPress

get_available_languages( string $dir = null ): string[]

Since
3.0.0, 4.7.0, 6.5.0
Source
wp-includes/l10n.php:1552
Gets all available languages based on the presence of *.mo and *.l10n.php files in a given directory.

Description

The default directory is WP_LANG_DIR.

Parameters

$dirstringoptional
A directory to search for language files. Default WP_LANG_DIR.Default: null

Return

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

Hooks fired · 1

One hook fires while get_available_languages() runs, in this order:

  1. apply_filters( get_available_languages )filterline 1580 (+28 into the body)

    Filters the list of available language codes.

Uses · 2

Used by · 13

Show all 13
  • wp_update_themes()Checks for available updates to themes based on the latest versions hosted on WordPress.org.

Source

function get_available_languages( $dir = null ) {	global $wp_textdomain_registry; 	$languages = array(); 	$path       = $dir ?? WP_LANG_DIR;	$lang_files = $wp_textdomain_registry->get_language_files_from_path( $path ); 	if ( $lang_files ) {		foreach ( $lang_files as $lang_file ) {			$lang_file = basename( $lang_file, '.mo' );			$lang_file = basename( $lang_file, '.l10n.php' ); 			if ( ! str_starts_with( $lang_file, 'continents-cities' ) && ! str_starts_with( $lang_file, 'ms-' ) &&				! str_starts_with( $lang_file, 'admin-' ) ) {				$languages[] = $lang_file;			}		}	} 	/**	 * Filters the list of available language codes.	 *	 * @since 4.7.0	 *	 * @param string[] $languages An array of available language codes.	 * @param string   $dir       The directory where the language files were found.	 */	return apply_filters( 'get_available_languages', array_unique( $languages ), $dir );}

History

Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.5.0
The initial file list is now cached and also takes into account *.l10n.php files.from the docblock
4.7.0
The results are now filterable with the 'get_available_languages' filter.from the docblock
3.0.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/l10n.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.