函数原型
get_available_languages( string $dir = null ): string[]
函数描述
Gets all available languages based on the presence of *.mo files in a given directory.
是否弃用
未弃用
函数参数
-
$dir
string
Optional - A directory to search for language files.
Default WP_LANG_DIR.Default:
null
函数返回值
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.
函数位置
File: wp-includes/l10n.php.
函数源码
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 );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 4.7.0 | The results are now filterable with the 'get_available_languages' filter. |
| 3.0.0 | Introduced. |

