From 80bd60fb88575ddbb8d2af17aa10f35182564c30 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Tue, 15 Nov 2016 01:18:37 +0000 Subject: [PATCH] I18N: Add the `get_available_languages` filter. Sometimes, a language file may not exist in exactly the format or location that `get_available_languages()` expects it to be in - for sites with this level of customisation, they need to be able to add their own language files to the list of those available. Props yoavf. Fixes #38788. git-svn-id: https://develop.svn.wordpress.org/trunk@39235 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/l10n.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/l10n.php b/src/wp-includes/l10n.php index 1827166b14..adb8483c73 100644 --- a/src/wp-includes/l10n.php +++ b/src/wp-includes/l10n.php @@ -948,6 +948,7 @@ function translate_user_role( $name ) { * The default directory is WP_LANG_DIR. * * @since 3.0.0 + * @since 4.7.0 The results are now filterable with the get_available_languages filter. * * @param string $dir A directory to search for language files. * Default WP_LANG_DIR. @@ -956,7 +957,7 @@ function translate_user_role( $name ) { function get_available_languages( $dir = null ) { $languages = array(); - $lang_files = glob( ( is_null( $dir) ? WP_LANG_DIR : $dir ) . '/*.mo' ); + $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' ); @@ -967,7 +968,15 @@ function get_available_languages( $dir = null ) { } } - return $languages; + /** + * Filters the list of available language codes + * + * @since 4.7.0 + * + * @param array $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 ); } /**