get_available_languages() - WordPress 函数参考中文文档

返回介绍

get_available_languages()

发布于 2017-09-10 字数 2957 浏览 983 评论 0

get_available_languages( string $dir = null )

Get all available languages based on the presence of *.mo files in a given directory.


描述

The default directory is WP_LANG_DIR.


参数

$dir

(string)
(Optional)
A directory to search for language files. Default WP_LANG_DIR.

Default value: null


返回值

(array) 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 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 );
}

更新日志

Version 描述
4.7.0 The results are now filterable with the ‘get_available_languages’ filter.
3.0.0 Introduced.

相关函数

Uses

  • wp-includes/l10n.php:
    get_available_languages
  • wp-includes/plugin.php:
    apply_filters()

Used By

  • wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php:
    WP_REST_Users_Controller::get_item_schema()
  • wp-includes/class-wp-locale-switcher.php:
    WP_Locale_Switcher::__construct()
  • wp-signup.php:
    signup_get_available_languages()
  • wp-admin/includes/translation-install.php:
    wp_install_language_form()
  • wp-admin/includes/translation-install.php:
    wp_download_language_pack()
  • wp-admin/includes/user.php:
    edit_user()
  • wp-includes/formatting.php:
    sanitize_option()
  • wp-includes/update.php:
    wp_update_plugins()
  • wp-includes/update.php:
    wp_update_themes()
  • Show 4 more used by
    Hide more used by


User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!