返回介绍

get_available_languages()

发布于 2017-09-10 22:49:20 字数 2955 浏览 1113 评论 0 收藏 0

get_available_languages( string $dir = null )

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


description

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

更新日志

Versiondescription
4.7.0The results are now filterable with the 'get_available_languages' filter.
3.0.0Introduced.

相关函数

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文