get_available_languages

函式
get_available_languages ( $dir = null )
引數
  • (string) $dir A directory to search for language files. Default WP_LANG_DIR.
    Required:
    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.
定義位置
相關方法
signup_get_available_languagesget_available_post_statuseswp_get_available_translationsget_editable_rolesget_available_post_mime_types
引入
3.0.0
棄用
-

get_available_languages函式是一個WordPress函式,用於檢索當前安裝的可用語言列表: 該函式返回一個物件陣列,每個物件代表一種在當前WordPress安裝中可以使用的語言。這些物件包含有關語言的資訊,例如它的名字、本地名稱和區域程式碼。

根據給定目錄下的*.mo檔案的存在,獲取所有可用的語言。

預設目錄是WP_LANG_DIR。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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 );
}
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 ); }
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 );
}

常見問題

FAQs
檢視更多 >