On this page
get_available_languages( string $dir = null ): string[]
Gets all available languages based on the presence of *.mo files in a given directory.
Description
The default directory is WP_LANG_DIR.
Parameters
$dirstring Optional-
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 .mo extension from the language file names.
Source
File: wp-includes/l10n.php. View all references
function get_available_languages( $dir = null ) {
$languages = array();
$lang_files = glob( ( is_null( $dir ) ? WP_LANG_DIR : $dir ) . '/*.mo' );
if ( $lang_files ) {
foreach ( $lang_files as $lang_file ) {
$lang_file = basename( $lang_file, '.mo' );
if ( 0 !== strpos( $lang_file, 'continents-cities' ) && 0 !== strpos( $lang_file, 'ms-' ) &&
0 !== strpos( $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', $languages, $dir );
}
Hooks
- apply_filters( 'get_available_languages',
string[] $languages ,string $dir ) -
Filters the list of available language codes.
Related
Uses
| Uses | Description |
|---|---|
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| 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() wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php | Retrieves the user’s schema, conforming to JSON Schema. |
| WP_Locale_Switcher::__construct() wp-includes/class-wp-locale-switcher.php | Constructor. |
| signup_get_available_languages() wp-signup.php | Retrieves languages available during the site/user sign-up process. |
| 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() wp-admin/includes/translation-install.php | Download a language pack. |
| login_footer() wp-login.php | Outputs the footer for the login page. |
| edit_user() wp-admin/includes/user.php | Edit user settings based on contents of $_POST |
| sanitize_option() wp-includes/formatting.php | Sanitizes various option values based on the nature of the option. |
| 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() wp-includes/update.php | Checks for available updates to themes based on the latest versions hosted on WordPress.org. |
| register_new_user() wp-includes/user.php | Handles registering a new user. |
Changelog
| Version | Description |
|---|---|
| 4.7.0 | The results are now filterable with the 'get_available_languages' filter. |
| 3.0.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_available_languages