Title: get_available_languages
Published: April 25, 2014
Last modified: August 20, 2026

---

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

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/get_available_languages/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/get_available_languages/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_available_languages/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_available_languages/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_available_languages/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_available_languages/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_available_languages/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/get_available_languages/?output_format=md#wp--skip-link--target)

Gets all available languages based on the presence of *.mo and *.l10n.php files 
in a given directory.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/get_available_languages/?output_format=md#description)󠁿

The default directory is WP_LANG_DIR.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_available_languages/?output_format=md#parameters)󠁿

 `$dir`stringoptional

A directory to search for language files.
 Default WP_LANG_DIR.

Default:`null`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_available_languages/?output_format=md#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.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_available_languages/?output_format=md#source)󠁿

    ```php
    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 );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/l10n.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/l10n.php#L1552)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/l10n.php#L1552-L1581)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_available_languages/?output_format=md#hooks)󠁿

 [apply_filters( ‘get_available_languages’, string[] $languages, string $dir )](https://developer.wordpress.org/reference/hooks/get_available_languages/)

Filters the list of available language codes.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_available_languages/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_Textdomain_Registry::get_language_files_from_path()](https://developer.wordpress.org/reference/classes/wp_textdomain_registry/get_language_files_from_path/)`wp-includes/class-wp-textdomain-registry.php` |

Retrieves translation files from the specified path.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

| Used by | Description | 
| [WP_REST_Plugins_Controller::create_item()](https://developer.wordpress.org/reference/classes/wp_rest_plugins_controller/create_item/)`wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php` |

Uploads a plugin and optionally activates it.

  | 
| [WP_REST_Users_Controller::get_item_schema()](https://developer.wordpress.org/reference/classes/wp_rest_users_controller/get_item_schema/)`wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php` |

Retrieves the user’s schema, conforming to JSON Schema.

  | 
| [WP_Locale_Switcher::__construct()](https://developer.wordpress.org/reference/classes/wp_locale_switcher/__construct/)`wp-includes/class-wp-locale-switcher.php` |

Constructor.

  | 
| [signup_get_available_languages()](https://developer.wordpress.org/reference/functions/signup_get_available_languages/)`wp-signup.php` |

Retrieves languages available during the site/user sign-up process.

  | 
| [wp_install_language_form()](https://developer.wordpress.org/reference/functions/wp_install_language_form/)`wp-admin/includes/translation-install.php` |

Output the select form for the language selection on the installation screen.

  | 
| [wp_download_language_pack()](https://developer.wordpress.org/reference/functions/wp_download_language_pack/)`wp-admin/includes/translation-install.php` |

Download a language pack.

  | 
| [login_footer()](https://developer.wordpress.org/reference/functions/login_footer/)`wp-login.php` |

Outputs the footer for the login page.

  | 
| [edit_user()](https://developer.wordpress.org/reference/functions/edit_user/)`wp-admin/includes/user.php` |

Edit user settings based on contents of $_POST

  | 
| [sanitize_option()](https://developer.wordpress.org/reference/functions/sanitize_option/)`wp-includes/formatting.php` |

Sanitizes various option values based on the nature of the option.

  | 
| [wp_update_plugins()](https://developer.wordpress.org/reference/functions/wp_update_plugins/)`wp-includes/update.php` |

Checks for available updates to plugins based on the latest versions hosted on WordPress.org.

  | 
| [wp_update_themes()](https://developer.wordpress.org/reference/functions/wp_update_themes/)`wp-includes/update.php` |

Checks for available updates to themes based on the latest versions hosted on WordPress.org.

  | 
| [register_new_user()](https://developer.wordpress.org/reference/functions/register_new_user/)`wp-includes/user.php` |

Handles registering a new user.

  |

[Show 7 more](https://developer.wordpress.org/reference/functions/get_available_languages/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_available_languages/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_available_languages/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.5.0](https://developer.wordpress.org/reference/since/6.5.0/) | The initial file list is now cached and also takes into account *.l10n.php files. | 
| [4.7.0](https://developer.wordpress.org/reference/since/4.7.0/) | The results are now filterable with the ['get_available_languages'](https://developer.wordpress.org/reference/hooks/get_available_languages/) filter. | 
| [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_available_languages%2F)
before being able to contribute a note or feedback.