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.


Built from https://develop.svn.wordpress.org/trunk@39235


git-svn-id: http://core.svn.wordpress.org/trunk@39175 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Gary Pendergast 2016-11-15 01:19:31 +00:00
parent 8e6753cead
commit fc1255a2c7
2 changed files with 12 additions and 3 deletions

View File

@ -948,6 +948,7 @@ function translate_user_role( $name ) {
* The default directory is WP_LANG_DIR. * The default directory is WP_LANG_DIR.
* *
* @since 3.0.0 * @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. * @param string $dir A directory to search for language files.
* Default WP_LANG_DIR. * Default WP_LANG_DIR.
@ -956,7 +957,7 @@ function translate_user_role( $name ) {
function get_available_languages( $dir = null ) { function get_available_languages( $dir = null ) {
$languages = array(); $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 ) { if ( $lang_files ) {
foreach ( $lang_files as $lang_file ) { foreach ( $lang_files as $lang_file ) {
$lang_file = basename( $lang_file, '.mo' ); $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 );
} }
/** /**

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.7-beta3-39234'; $wp_version = '4.7-beta3-39235';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.